Button with responsive image

Asked

Viewed 418 times

0

I have several buttons that readjust depending on the size of the device, however, the images inserted in it do not automatically adjust, and end up always with a fixed size. How can I make these images responsive?

<ImageView
    android:id="@+id/imagem2"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:layout_gravity="center"
    android:background="#9b1136"
    android:src="@drawable/logove2" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/botaoEmpresa"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" 
        android:drawableTop="@drawable/empresas"
        android:text="Empresas"
        />

    <Button
         android:id="@+id/botaoContato"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" 
        android:drawableTop="@drawable/contato"
        android:text="Contato"

        />

    <Button
        android:id="@+id/botaoRede"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" 
         android:drawableTop="@drawable/redes"
         android:text="Redes Sociais"
        />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="horizontal" >

    <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
       android:drawableTop="@drawable/servicosuteis"
       android:text="Serviço uteis"
        android:layout_weight="1" />

   <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:drawableTop="@drawable/desconto"
        android:text="Mult  Desconto"
        android:layout_weight="1" />
   <Button
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:drawableTop="@drawable/revista"
        android:text="Revista"
        android:layout_weight="1" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"

    android:orientation="horizontal" >

    <Button
        android:id="@+id/botaoRegiao"
        android:layout_width="0dp"
        android:layout_height="match_parent"

       android:drawableTop="@drawable/mapa2"
       android:text="Altere sua região"
        android:layout_weight="1" />


</LinearLayout>

I wanted the images inside him to readjust, how can I solve this problem?

1 answer

0


Wrap each Linearlayout in a Framelayout.

A classic example:

<? xml version = "1.0" encoding = "utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.25">
            <LinearLayout
                android:id="@+id/linear1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="horizontal">
                <ImageButton
                    android:id="@+id/imageButton2"
                    android:layout_width="0dp"
                    android:layout_weight="0.40"
                    android:layout_height="fill_parent"
                    android:src="@drawable/ic_pages" />
                <ImageButton
                    android:id="@+id/imageButton1"
                    android:layout_width="0dp"
                    android:layout_weight="0.60"
                    android:layout_height="fill_parent"
                    android:src="@drawable/ic_pages" />
            </ LinearLayout>
        </ FrameLayout>
    </ LinearLayout>
</ RelativeLayout>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.