2017-06-05 91 views
0

我想在每個列表項中排列文本視圖,以便textview(id:lnumber)位於左側,textview(id:lname)位於其旁邊,textview(id :lname1)下的TextView(編號:L-NAME)Android,textviews中的textviews對齊

我能夠對準前兩個textviews但我無法安排第三,正下方的第二

list_item.xml

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

    <TextView 
     android:id="@+id/lnumber" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:paddingBottom="20dip" 
     android:paddingTop="20dip" 
     android:paddingLeft="10dip" 
     android:textColor="@android:color/black" 
     android:textSize="16sp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/lname" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_alignParentRight="true" 
     android:paddingBottom="20dip" 
     android:paddingTop="20dip" 
     android:paddingLeft="10dip" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:textSize="17sp" 
     android:textColor="@android:color/black" /> 

    <TextView 
     android:id="@+id/lname1" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/lname" 
     android:paddingBottom="20dip" 
     android:paddingTop="20dip" 
     android:paddingLeft="10dip" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:textSize="17sp" 
     android:textColor="@android:color/black" /> 

    </LinearLayout> 

回答

0

您可以使用此

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

<TextView 
    android:id="@+id/lname" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Number" /> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/lnumber" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Name" /> 

    <TextView 
     android:id="@+id/lnumber1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Some Text" /> 

</LinearLayout> 

添加一些填充,以滿足您的需求。

0

使用這個:

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

    <TextView 
     android:id="@+id/lnumber" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingBottom="20dip" 
     android:paddingTop="20dip" 
     android:paddingLeft="10dip" 
     android:textColor="@android:color/black" 
     android:textSize="16sp" 
     android:textStyle="bold" 
     /> 

    <TextView 
     android:id="@+id/lname" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:paddingBottom="20dip" 
     android:gravity="end" 
     android:paddingTop="20dip" 
     android:paddingLeft="10dip" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:textSize="17sp" 
     android:textColor="@android:color/black" 
     /> 

    <TextView 
     android:id="@+id/lname1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/lname" 
     android:layout_alignStart="@+id/lname" 
     android:paddingBottom="20dip" 
     android:paddingTop="20dip" 
     android:paddingLeft="10dip" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:textSize="17sp" 
     android:textColor="@android:color/black"/> 



</RelativeLayout> 
0

您可以使用RelativeLayout。或在第一個LinearLayout中使用另一個LinearLayout,只需在新的LinearLayout中創建textview2和textview3即可。