各位大虾,再这里有一个问题困扰了狠久,就是ListView 中item背景的问题
我的listView的xml 是这样写的
- XML code
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:id="@+id/listView1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:listSelector="@drawable/list_item_selected" android:drawSelectorOnTop="true" android:divider="@null" android:cacheColorHint="#00000000" android:focusable="true" > </ListView></LinearLayout>
其中对应的list_item_selected如下
- XML code
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/list_bg_focus" /> <item android:state_focused="true" android:drawable="@drawable/list_bg_focus" /> <item android:state_pressed="false" android:state_focused ="false" android:drawable="@drawable/list_bg_normal" />
在listitem的xml中就是一般的布局了
当程序运行后listView 默认的背景不显示出来,当按下的时候能有按下的背景出来
如果我在listitem的layout中设置Background的话,默认背景是出来了,但是按下的背景没有出来,按下的背景被listitem中的默认背景给覆盖了
我想问下各位,怎么样才能达到我的要求呢?
就是没有按下的状态下显示list_bg_normal 这个背景,如果有按下则显示list_bg_focus这个背景?
我用的是Android2.1sdk开发的
------解决方案--------------------
覆写public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3){
}方法
方法里加上
arg1.setBackgroundResource(R.drawable.list_bg_focus);