在列表视图背景的每一行 [英] Background each row in listview

查看:113
本文介绍了在列表视图背景的每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图定义一个的ListView 有一个默认的背景图像和突出的背景图像的每个一行。

I'm trying to customize a ListView to have a default background image and highlighted background image for each single row.

不过,高亮背景图片会影响单个行,默认背景图片会影响整个的ListView ;但我需要它来影响每个一行。

However, the highlighted background image affects single rows, and the default background image affects the whole ListView; but I need it to affect each single row.

有人能告诉我如何做到这一点?

Could somebody tell me how to do this?

这是我的code:

布局/ main.xml中:

<ListView
 android:id="@+id/list"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:dividerHeight="1dip"       
 android:listSelector="@drawable/bg_highlighted"
/>

绘制/ selector.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_selected="true" android:drawable="@drawable/bg_default"/>
<item android:state_focused="true" android:drawable="@drawable/bg_default"/>

</selector>

的src / main.java:

   ArrayAdapter<String> adapter = new ArrayAdapter<String>(
            this,R.layout.list, mStrings); /*"Item1","Item2","Item3","Item4"*/
    ListView lv = (ListView)findViewById(R.id.list);
    lv.setAdapter(adapter);
    lv.setBackgroundResource(R.drawable.selector);

作为默认背景和突出的背景我用PNG图片。

As default background and highlighted background I use png images.

这是我的,但是的这就是我要的

推荐答案

这篇关于在列表视图背景的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆