2013-12-13 101 views
0

我想使用2個TextView和2個ImageViews做一個ListView。 enter image description hereAndroid,listView,我的文本不符合要求

我想要「位置」TextView是在「名稱」TextView下,而不是在右邊!

下面的代碼至今XML的:

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

    android:layout_width="fill_parent" 
    android:height="?android:attr/listPreferredItemHeight" 
    android:orientation="vertical"> 

    <View 
     android:layout_width="fill_parent" 
     android:layout_height="2px" 
     android:background="?android:attr/listDivider" /> 


    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/list_item_widget_text" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:gravity="center_vertical" /> 

     <TextView 
      android:id="@+id/widget42" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="Location" 
      android:layout_below="@+id/list_item_widget_text"/> 

     <ImageView 

      android:layout_height="fill_parent" 
      android:layout_width="wrap_content" 
      android:src="@drawable/list_vertical_divider" /> 

     <ImageView 
      android:id="@+id/list_item_widget_edit" 
      android:background="@drawable/list_item_widget_bg" 
      android:src="@android:drawable/ic_menu_edit" 
      android:layout_height="fill_parent" 
      android:layout_width="50dip"/> 

     <ImageView 

      android:layout_height="fill_parent" 
      android:layout_width="wrap_content" 
      android:src="@drawable/list_vertical_divider" /> 

     <ImageView 
      android:id="@+id/list_item_widget_delete" 
      android:background="@drawable/list_item_widget_bg" 
      android:src="@android:drawable/ic_menu_delete" 
      android:layout_height="fill_parent" 
      android:layout_width="50dip" /> 


    </LinearLayout> 
</LinearLayout> 

預先感謝您!

回答

0

裹2 TextViewLinearLayout這樣

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="fill_parent" 
    android:layout_weight="1" 
    android:orientation="vertical">  

     <TextView 
      android:id="@+id/list_item_widget_text" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:gravity="center_vertical" /> 

     <TextView 
      android:id="@+id/widget42" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="Location" 
      android:layout_below="@+id/list_item_widget_text"/> 
<LinearLayout> 
0

雖然Apoorv的方法也很不錯,我寧願使用RelativeLayout代替LinearLayout的是,它會給你更多的靈活性:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:height="?android:attr/listPreferredItemHeight" 
    android:orientation="vertical"> 

    <View 
     android:layout_width="fill_parent" 
     android:layout_height="2px" 
     android:background="?android:attr/listDivider" /> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <TextView 
      android:id="@+id/list_item_widget_text" 
      android:layout_width="0dp" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:layout_alignParentLeft="true" 
      android:gravity="center_vertical" /> 

     <TextView 
      android:id="@+id/widget42" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:text="Location" 
      android:layout_below="@+id/list_item_widget_text"/> 

     <ImageView 
      android:id="@+id/divider1" 
      android:layout_height="fill_parent" 
      android:layout_width="wrap_content" 
      android:layout_toLeftOf="@+id/list_item_widget_edit" 
      android:src="@drawable/list_vertical_divider" /> 

     <ImageView 
      android:id="@+id/list_item_widget_edit" 
      android:background="@drawable/list_item_widget_bg" 
      android:src="@android:drawable/ic_menu_edit" 
      android:layout_height="fill_parent" 
      android:layout_toLeftOf="@+id/divider2" 
      android:layout_width="50dip"/> 

     <ImageView 
      android:id="@+id/divider2" 
      android:layout_height="fill_parent" 
      android:layout_width="wrap_content" 
      android:layout_toLeftOf="@+id/list_item_widget_delete" 
      android:src="@drawable/list_vertical_divider" /> 

     <ImageView 
      android:id="@+id/list_item_widget_delete" 
      android:background="@drawable/list_item_widget_bg" 
      android:src="@android:drawable/ic_menu_delete" 
      android:layout_alignParentRight="true" 
      android:layout_height="fill_parent" 
      android:layout_width="50dip" /> 


    </RelativeLayout> 
</LinearLayout>