我需要添加添加复杂项目背景的 ListView: 不同的偶数/奇数和圆角在顶部和底部。它看起来像这样:
我已经通过 level-list 实现了所有这些东西,但是还有一件事我想做。 现在底部的项目接近屏幕的底部。最好添加一些空间。
我不想添加底部页边距到 ListView,我只需要最后一个项目的页边距。
我认为这样做的方式是:
一种将空 TextView 添加到 ListView 的 hack-add 页脚。但是页脚是相当不稳定的东西,它们通常在 notifyDataSetChanged 之后消失,而且无法恢复它们
我要求设计师添加透明像素底部的背景资源。不幸的是,在这种情况下,垂直居中是完全打破。 例如,有这样的9个补丁:
布局如下:
<?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"
>
<!-- View with background with transparent pixels on bottom -->
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:id="@+id/item"
android:background="@drawable/some_bgr"
android:padding="10dp"
>
<TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"
android:text="Title"
android:layout_gravity="center"
android:textSize="18sp"
/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Detail"
android:layout_gravity="center"
android:textSize="18sp"
/>
</LinearLayout>
<!-- Just for marking place took by view -->
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_below="@id/item"
android:background="#88ff55"
/>
</RelativeLayout>
结果是:
正如你所看到的,定心不起作用,很不幸。 (顺便说一句,如果指定这个9补丁作为 TextView 的背景,居中很好。如果你知道任何文章,解释这一点,请让我知道。)
应该可以,但是不知道为什么我还是不能修好。 我不喜欢这种方式,因为我不喜欢在代码中修改维度。
已经有一种想象的方法——用特定的位图和边距构造一些可绘制的 XML。根据可绘制的概念,这应该是可能的,但我无法找到实现。也许有人知道?
还有别的办法吗?