Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change gravity of image drawable in textview

I've added image Drawable start in a TextView . Problem is i cant control the gravity of that Drawable in TextView

What i need to achieve What i need to achieve

What i have achieved so far

What i have achieved so far

This is my TextView

        <TextView
            android:id="@+id/tv_8_digit_check"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:drawablePadding="@dimen/dimen_4"
            android:drawableStart="@drawable/ic_validate"
            android:text="@string/at_least_8_characters_txt"
            android:textColor="@color/white_trans"
            android:textSize="12sp" />

Any suggestion on how can i set gravity of that Drawable to top/start? Thanks

like image 890
Usman Ghauri Avatar asked Feb 27 '17 08:02

Usman Ghauri


4 Answers

  1. Try using android:gravity="top"

    if it didnt work then go with negative margin like this

  2. android:drawablePadding="-20sp"

  3. Another alternative way is to take an ImageView beside TextView inside LinearLayout so you can apply gravity

like image 135
Manohar Avatar answered Nov 08 '22 17:11

Manohar


Use checkbox instead of textview Drawable, and add custom drawable where you can use this image

like image 33
Jinal Patel Avatar answered Nov 08 '22 15:11

Jinal Patel


I suggest you put image to imageview. Put the imageview and the textview in a Linearlayout and set gravity to top. Reduce the size of text and image too.

like image 1
K.Sopheak Avatar answered Nov 08 '22 17:11

K.Sopheak


<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="top">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="@dimen/dimen_4"
        android:src="@drawable/ic_validate"/>
    <TextView
        android:id="@+id/tv_8_digit_check"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/at_least_8_characters_txt"
        android:textColor="@color/white_trans"
        android:textSize="12sp" />

</LinearLayout>
like image 1
Davit Avetisyan Avatar answered Nov 08 '22 15:11

Davit Avetisyan