如何制作全屏列表视图行
how to make full screen listview rows
我的应用程序中有一个列表视图,我想让它的行全屏显示。
我把所有东西都设置为 match_parent 但它没有用。
它只占屏幕的一半。
我该怎么做?
这是我的列表视图代码:
<ListView
android:id="@+id/listviewFactoriPortfolio"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
这是我为每一行自定义的布局:
<?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"
android:layout_margin="5dp"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp" >
<ImageView
android:id="@+id/imgImageItem"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:padding="5dp"
android:scaleType="fitXY"
android:src="@drawable/photo_2" />
<TextView
android:id="@+id/txtNameItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:gravity="center"
android:padding="5dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/txtExplainItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txtNameItem"
android:layout_margin="5dp"
android:gravity="center"
android:padding="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/txtCostItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imgImageItem"
android:layout_alignParentBottom="true"
android:layout_margin="5dp"
android:gravity="center"
android:padding="5dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/txtDestributeDateItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/txtCostItem"
android:layout_margin="5dp"
android:gravity="center"
android:padding="5dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/txtAddressItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/txtDestributeDateItem"
android:layout_margin="5dp"
android:gravity="center"
android:padding="5dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
尝试将此添加到适配器的 getView() 中:
view.getLayoutParams().height = viewGroup.getHeight() / getCount();
view.requestLayout();
我的应用程序中有一个列表视图,我想让它的行全屏显示。
我把所有东西都设置为 match_parent 但它没有用。
它只占屏幕的一半。
我该怎么做?
这是我的列表视图代码:
<ListView
android:id="@+id/listviewFactoriPortfolio"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
这是我为每一行自定义的布局:
<?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"
android:layout_margin="5dp"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp" >
<ImageView
android:id="@+id/imgImageItem"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:padding="5dp"
android:scaleType="fitXY"
android:src="@drawable/photo_2" />
<TextView
android:id="@+id/txtNameItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:gravity="center"
android:padding="5dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/txtExplainItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/txtNameItem"
android:layout_margin="5dp"
android:gravity="center"
android:padding="5dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/txtCostItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imgImageItem"
android:layout_alignParentBottom="true"
android:layout_margin="5dp"
android:gravity="center"
android:padding="5dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/txtDestributeDateItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/txtCostItem"
android:layout_margin="5dp"
android:gravity="center"
android:padding="5dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/txtAddressItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/txtDestributeDateItem"
android:layout_margin="5dp"
android:gravity="center"
android:padding="5dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
尝试将此添加到适配器的 getView() 中:
view.getLayoutParams().height = viewGroup.getHeight() / getCount();
view.requestLayout();