2013-01-11 26 views
1

我试图在我的列表视图中对齐行元素。 我有这码布局行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" > 

    <TextView 
     android:id="@+id/TV_list_from_db_p_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Medium Text" 
     android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="15dp" > 

     <Button 
      android:id="@+id/BTN_addOne_from_db" 
      android:layout_width="33dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/button" 
      android:onClick="addOneToQuantity" 
      android:text="+" /> 

     <EditText 
      android:id="@+id/TV_Quantity_from_db" 
      android:layout_width="44dp" 
      android:layout_height="32dp" > 
     </EditText> 

     <Button 
      android:id="@+id/BTN_subOne_from_db" 
      android:layout_width="33dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/button" 
      android:onClick="subOneToQuantity" 
      android:text="-" /> 
    </LinearLayout> 

    <CheckBox 
     android:id="@+id/CHK__list_from_db" 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
    /> 

</LinearLayout> 

This code gives me this: 我想要的元素 对齐,现在它通过文本视图

这样的长度对齐:
| TextView |号码选取器|复选框|
| TextView | Number Picker |复选框|
| TextView | Number Picker |复选框|

任何想法?

+1

使用表格布局? (或者,如果您确实需要列表视图,则在标签后面使用固定大小的视图,标签的宽度为0重量1) – njzk2

回答

2

由于您使用的LinearLayout,你可以给内部的LinearLayout和复选框都layout_width="wrap_content",给TextView的layout_width="0dp"layout_weight="1"

0

使用相对布局,并把这些顺序:

Check box - align parent right - width="30dp" 
Button1 - to left of check box - width="33dp" 
Edit Text - to left of Button1 - width="44dp" 
Button2 - to left of Edit Text - width="33dp" 
TextView - align parent left and to left of Button2 - width wrap_content