【发布时间】:2014-04-25 18:30:27
【问题描述】:
我正在使用 ListView,它有页眉和页脚。问题是我需要项目列表本身比标题更窄。而我无法做到这一点。问题是,如果我为 ListView 设置填充或边距,它将被设置为列出项目、页眉和页脚(由于某种原因,页眉和页脚会比列表项目更窄)。仅为项目布局本身设置边距是没有用的。以下是布局:
main_layout.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
header_list_layout.xml:
<?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" >
<EditText
android:inputType="textPersonName" />
</RelativeLayout>
footer_list_layout.xml:
<?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" >
<TextView
android:layout_width ="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
list_item_layout.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="wrap_content"
android:orientation="vertical" >
<TextView
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextView>
</LinearLayout>
那么我该怎么做才能使一切正常呢?
我希望它看起来如何的图像:
【问题讨论】:
标签: android listview android-listview margins