Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : Drawable next to TextView with weight to each TextView in LinearLayout

I am trying to achieve the result as shown in Pic1. Tried setting gravity, paddingleft etc but the drawable image comes in the right end and not next to Text(SHown in Pic 2enter image description here). Can anyone suggest how to align the image next to TextView? Also how to set the size of drawable?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" 
android:background="@drawable/separator"
    android:padding="10dp">

<TextView
    android:id="@+id/sms"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="2dp"
    android:layout_marginRight="2dp"
    android:layout_weight="1"
    android:drawableEnd="@drawable/message"
    android:drawableRight="@drawable/message"
    android:gravity="center"
    android:paddingLeft="3dp"
    android:paddingRight="3dp"
    android:text="SMS" />

<TextView
    android:id="@+id/call"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:drawableEnd="@drawable/call"
    android:drawableRight="@drawable/call"
    android:gravity="center"
    android:text="CALL" />

<TextView
    android:id="@+id/email"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center"
    android:drawableEnd="@drawable/mail"
    android:drawablePadding="3dp"
    android:drawableRight="@drawable/mail"
    android:text="MAIL" />

like image 365
kumar Avatar asked Oct 29 '15 04:10

kumar


1 Answers

Try to build around this.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"
    android:orientation="horizontal"
    android:padding="10dp">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_weight="1">

        <TextView
            android:id="@+id/sms"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="2dp"
            android:gravity="center"
            android:drawableRight="@drawable/message"
            android:text="SMS" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_weight="1">

        <TextView
            android:id="@+id/call"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableRight="@drawable/call"

            android:gravity="center"
            android:text="CALL" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_weight="1">

        <TextView
            android:id="@+id/email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableRight="@drawable/mail"
            android:gravity="center"
            android:text="MAIL" />
    </LinearLayout>
</LinearLayout>

enter image description here

like image 180
Dhinakaran Thennarasu Avatar answered Nov 13 '22 09:11

Dhinakaran Thennarasu