Android ListView 滚动时背景样式问题
我需要设置 ListView 的样式,但不明白为什么滚动时它会变成黑色背景。我在 LinearLayout 中有 ListView,并且该布局将背景设置为图像。
这就是我对 ListView 的看法:
<style name="MyListView" parent="@android:style/Widget.ListView">
<item name="android:listSelector">@drawable/selector_list_item</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_focused="true"
android:drawable="@drawable/shape_list_item_normal" />
<item android:state_pressed="true"
android:drawable="@drawable/shape_list_item_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/shape_list_item_normal" />
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#80ffffff" android:endColor="#80eff3ef" android:angle="45" />
<padding android:left="5dip" android:right="5dip" android:top="7dip" android:bottom="7dip"/>
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#80808080" android:endColor="#80eff3ef" android:angle="45" />
<padding android:left="5dip" android:right="5dip" android:top="7dip" android:bottom="7dip"/>
</shape>
当我应用 MyListView 样式时,我没有看到太多事情发生。当我单击项目时 - 是的,我看到渐变。当 ListView 稳定时 - 我看到背景应该来自父布局。当我滚动时 - 我看到黑色背景,它正在擦除父母的背景。如果我知道如何用其他东西来设置它,我会同意的。
I need to style ListView and can't figure out why It turns to black background when scroll.. I have ListView inside LinearLayout and that layout has Background set to image.
This is what I have for ListView:
<style name="MyListView" parent="@android:style/Widget.ListView">
<item name="android:listSelector">@drawable/selector_list_item</item>
</style>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_focused="true"
android:drawable="@drawable/shape_list_item_normal" />
<item android:state_pressed="true"
android:drawable="@drawable/shape_list_item_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/shape_list_item_normal" />
</selector>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#80ffffff" android:endColor="#80eff3ef" android:angle="45" />
<padding android:left="5dip" android:right="5dip" android:top="7dip" android:bottom="7dip"/>
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#80808080" android:endColor="#80eff3ef" android:angle="45" />
<padding android:left="5dip" android:right="5dip" android:top="7dip" android:bottom="7dip"/>
</shape>
When I apply MyListView style I don't see much happening. When I click on item - yes, I see gradient. When ListView stable - I see background as it should be from parent layout. When I scroll - I see black background, it's erasing parent's background. And I would be fine with that if I knew how to set it with something else..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在listView的xml中使用以下属性:
Use the following property in the xml of listView:
在列表视图的 xml 中尝试以下代码行:
android:listSelector="@android:color/transparent"
Try this line of code in the xml of your listview:
android:listSelector="@android:color/transparent"
如果您需要在
PreferenceActivity
中使用透明的ListView
,请尝试使用主题并将该主题放入您的
AndroidManifest.xml
If you require transparent
ListView
in aPreferenceActivity
, try using a theme withAnd put the theme in your
AndroidManifest.xml