LinearLayout权重在Listview中不起作用
这个问题在这里已经有了答案:
使TextView的layout_width为0dp。
<?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="wrap_content"
android:background="@drawable/border"
android:orientation="horizontal"
android:weightSum="3">
<TextView
android:id="@+id/txt_rating"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="@dimen/margin_10"
android:text="Rating"
android:textAlignment="center"
android:textColor="@color/colorPrimaryDark" />
<TextView
android:id="@+id/txt_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxEms="10"
android:padding="@dimen/margin_10"
android:singleLine="true"
android:text="Companay"
android:textAlignment="center"
android:textColor="@color/colorPrimaryDark"
/>
<TextView
android:id="@+id/txt_sector"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxEms="10"
android:padding="@dimen/margin_10"
android:singleLine="true"
android:text="Sector"
android:textAlignment="center"
android:textColor="@color/colorPrimaryDark" />
</LinearLayout>
if u want to use weight to set your height of textview , then u must first `
<TextView
android:id="@+id/txt_sector"
android:layout_width="wrap_content"
android:layout_height="0dp" // Change is done here
android:layout_weight="1"
android:ellipsize="end"
android:maxEms="10"
android:padding="@dimen/margin_10"
android:singleLine="true"
android:text="Sector"
android:textAlignment="center"
android:textColor="@color/colorPrimaryDark" />`
similarly if u r looking to set width , u can use width="0dp" and wieght="1"
链接地址: http://www.djcxy.com/p/93257.html