gpt4 book ai didi

Android:ListView 的边距/填充没有应用于页眉的边距?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:39:55 26 4
gpt4 key购买 nike

是否可以在不将边距应用到页眉的情况下为 ListView 设置边距/填充?我希望我的 ListView 像 Google Now 布局一样。除了这个小问题,我一切正常。

问题:是否可以不将 ListView 的布局参数应用于其标题?

编辑 1:更多信息

紫色 View 是 ListView 的标题。我已经尝试在列表项布局中添加边距。这也不起作用。我所需要的只是一种将边距应用到 ListView 的方法,这样它就不会将边距应用到 ListView 中的标题。

编辑2:我的布局标题.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>

根目录.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>

由于这篇文章的篇幅,我在这里删除了无用的布局属性。 This is how it looks

最佳答案

经过大量挖掘后,我发现无法将 listView 布局参数与其 header 分离,并且 header 是 listView 的一部分。因此,为了获得所需的边距效果,环顾四周后,我发现在 ListView 项目中向布局的根部添加边距是行不通的。所以我在现有的根 LinearLayout(嵌套的 LinearLayout)中添加了另一个虚拟 LinearLayout,并在嵌套的布局中添加了子项。现在将边距设置为内部布局会产生所需的效果。

代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:background="@drawable/list_selector"
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>

</LinearLayout>

关于Android:ListView 的边距/填充没有应用于页眉的边距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14051090/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com