2016-08-10 1 views
-2

Посмотрите на изображение моего снимка экрана, и я использую изображение, чтобы указать свой вопрос. enter image description hereВопрос о ui

Ниже мой код макета:

<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="你好" /> 

результат макета так же, как изображение выше, мои сомнения в том, что почему текст находится далек от вытяжки, и я хочу, чтобы в результате: enter image description here

Я пытаюсь установить drawablepadding меньше нуля, но это не работает, как я могу сделать для этого, я только хочу использовать этот путь, не хотят использовать TextView и ImageView, благодаря продвинутым.

+0

'андроид: гравитация = "центр"' для Align TextView центра и 'андроида: самотеком = "центр | правых"' для Align TextView справа. – user392117

ответ

0

Вот еще одно хакерское решение. Попробуйте это :)

Фокус в том, что вы положили invisible View between your TextViews, и ваш текстовый рисунок будет иметь простой wrap_content как ширину.

<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> 

После этого нет необходимости в гравитации вправо, но только в центре тяжести. Надеюсь, поможет!

proof of code

+0

это нормально, спасибо –

+0

приветствую :) – petin