【发布时间】:2012-12-27 07:32:43
【问题描述】:
是否可以在不将边距应用于标题的情况下为 ListView 设置边距/填充?我希望我的 ListView 类似于 Google Now 布局。除了这个小问题,我什么都做。
问题:是否可以不将 ListView 的布局参数应用于其标题?
EDIT1:更多信息
紫色视图是列表视图的标题。 我尝试在列表项布局中添加边距。这也不起作用。 我需要的只是一种将边距应用于列表视图的方法,以便它不会将边距应用于列表视图中的标题。
编辑2: 我的布局 header.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="@dimen/top_height"
android:background="@color/top_item" />
<View
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="@dimen/sticky_height"
android:layout_gravity="bottom" />
</FrameLayout>
root_list.xml
<LinearLayout>
<com.test.CustomListView
android:id="@android:id/list"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_height="wrap_content" /></LinearLayout>
list_item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/card_background"
android:orientation="vertical" >
<TextView
android:id="@+id/textview_note"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textview_note_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"/></LinearLayout>
由于这篇文章的篇幅,我在这里删除了无用的布局属性。
【问题讨论】:
-
对所有项目平等地应用填充,并且不对标题视图应用填充。
-
我认为您的意思是向 listItem 布局添加边距。它不起作用。
-
我的意思是为每个列表项布局项添加填充。并且不要在 Header 中添加相同的内容。
-
您的意思是以编程方式为适配器的列表视图中的每个项目添加填充?
-
如果您添加项目布局代码,那么我可以建议。我建议您不要以编程方式更改项目布局
标签: android android-layout android-listview