Android的ListView的填充内容不移动的ListView的高度?高度、内容、Android、ListView

2023-09-04 10:54:24 作者:奶昔味的小仙女

我有一大堆里面的物品一个ListView。如何让我的顶部和底部的项目有10dp的上边距顶级项目,10dp的底部项目的底部边缘?现在,我可以做到这一点与填充或利润率在ListView但结果是,当你滚动的ListView的边缘,现在从屏幕底部10dp。无论如何围绕这吗?我自己也尝试设置我的适配器的getView方法里面的利润,但我没有看到任何AbsListView.LayoutParams保证金选项。任何帮助将是巨大的。

I have a ListView with a bunch of items inside it. How do I make the top and bottom items have a top margin of 10dp for top item and bottom margin of 10dp for bottom item? Now I can do this with padding or margin on the ListView but the result is that when you scroll the edge of the ListView is now 10dp from the bottom of the screen. Anyway around this? I have also tried setting margins inside of the getView method of my adapter but I don't see any margin options for AbsListView.LayoutParams. Any help would be great.

感谢

推荐答案

关键是要包括安卓clipToPadding =假在视图定义,如:

The trick is to include android:clipToPadding="false" in your view definition, e.g.:

<ListView android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="16dip"
    android:paddingBottom="16dip"
    android:clipToPadding="false" />