我的一个ViewPager片段中有一个ListView,我希望在滚动之前只显示三个项目。我想这样做是因为我的ViewPager背景在屏幕底部包含一个图像,当ListView延伸到屏幕底部时,图像模糊了列表项的细节。
有人有建议吗?
我尝试将该片段的背景更改为纯色,但由于某种原因,整个片段的屏幕是白色而不是我选择的颜色。 我也尝试实现自己的选择器,以获得每个列表项的默认背景,但我似乎无法使默认选择器工作。
如果有人认为这是正确的路线,我的选择器代码就会如此。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false" android:drawable="@drawable/list_item_gradient"/>
<item android:state_pressed="true" android:drawable="@drawable/list_item_pressed"/>
<item android:state_focused="true" android:drawable="@drawable/list_item_focused"/>
<item android:drawable="@drawable/list_item_default" />
</selector>
我的listView布局是:
<?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">
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true">
</ListView>
<TextView android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/no_addresses" />"
</RelativeLayout>