2015年5月25日 星期一

ListView的item中設定元件layout_weight

目的:

在listview的item中設定元件layout_weight

操作:

  1. 在item的xml中,每個元件設定layout_weight
  2. listview的設定,layout_width="match_parent"

Code:

main.xml

    <ListView
        android:id="@+id/totalReview_detailLV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>




item.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:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2" >
    </TextView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </TextView>

</LinearLayout>

reference:
http://stackoverflow.com/a/28078042

沒有留言:

張貼留言