-2

look at the image of my screenshot, and I use the image to state my question.enter image description here

The following is my code of layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >

<TextView
    android:id="@+id/one"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:drawableRight="@drawable/hexun_dh6"
    android:gravity="center_vertical"
    android:text="你好" />

<TextView
    android:id="@+id/two"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:drawableRight="@drawable/hexun_dh6"
    android:gravity="center_vertical"
    android:text="你好" />

<TextView
    android:id="@+id/three"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:drawableRight="@drawable/hexun_dh6"
    android:gravity="center_vertical"
    android:text="你好" />

<TextView
    android:id="@+id/four"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:drawableRight="@drawable/hexun_dh6"
    android:gravity="center_vertical"
    android:text="你好" />

the layout result is just like above image,my doubt is that why the text is far away of drawable,and I want to the result:enter image description here

I try set the drawablepadding less than zero,but it doesn't work, how I can do for that, I only want to use this way ,don't want to use TextView and ImageView ,thanks advanced.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Json zhang
  • 119
  • 14

1 Answers1

0

Here is another hacky solution. Try this one :)

The trick is that you put invisible View between your TextViews and your textViews will have simple wrap_content as width.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/one"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableRight="@drawable/big_star_orange"
        android:gravity="center"
        android:text="你好" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/two"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableRight="@drawable/big_star_orange"
        android:gravity="center"
        android:text="你好" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/three"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableRight="@drawable/big_star_orange"
        android:gravity="center"
        android:text="你好" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="1" />

    <TextView
        android:id="@+id/four"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableRight="@drawable/big_star_orange"
        android:gravity="center"
        android:text="你好" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight="1" />
</LinearLayout>

After that there is no need for gravity right, but the gravity center only. Hope it helps!

proof of code

petin
  • 629
  • 5
  • 13