2016-09-27 4 views
-3

Написав приложение для Android, я столкнулся с некоторыми трудностями в настройке ListView.Разбиение строк ListView на Android

Мне нужно иметь три TextView s в ряд, первый из которых должен быть выровнен слева, второй к центру и последнему справа.

Можно ли это сделать только через XML? Или, если нет, как это достичь?

ответ

1

Вы можете сделать использование атрибута layout_weight в простой горизонтальной LinearLayout:

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

    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="left" 
     android:text="first"/> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="second"/> 
    <TextView 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="right" 
     android:text="third"/> 

</LinearLayout> 
0

Пожалуйста, проверьте этот XML-код:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:weightSum="3"> 

<TextView 
    android:id="@+id/tv_left" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:gravity="center" 
    android:text="Left"/> 

<TextView 
    android:id="@+id/tv_center" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:gravity="center" 
    android:text="Center"/> 

<TextView 
    android:id="@+id/tv_right" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:gravity="center" 
    android:text="Right"/> 

    </LinearLayout> 
Смежные вопросы