设置与选择ImageView的背景问题 [英] Setting imageView background issue with selector
问题描述
我有一个问题,在列表视图中项目设置的Click事件。
I have a problem with setting the click event in a list view item.
这是该列表是如何在默认情况下显示:
This is how the list is shown in the default situation:
这是它的外观时,我preSS红色的图像(红色变成蓝色):
This is how it looks when I press the red image (the red turns to blue):
这是当我preSS列表项:
and this is when I press the list item:
正如你所看到的,红色的图像变成蓝色也,虽然我没pressed按钮。我要的是,当我preSS列表项有红色图像没有变化,它仍然是相同的。
As you can see, the red image turns to blue also, Even though I didn't pressed the button. What I want is that when I press the list item there is no change to the red image, and it remains the same.
我尝试添加的android:drawSelectorOnTop =真正的
在列表视图部分XML文件,但没有奏效。我也尝试没有成功与选择的参数来修复它,仍然
I tried to add android:drawSelectorOnTop="true"
to xml file in listview section, but it didn't work. I also tried to fix it with the selector parameters, still with no success.
我上传了一些code,接下来的部分是在不同的XML文件,所以不要混淆。
I uploaded some code, the next sections are in different xml files, so don't get confused.
编辑:我想使用的OS项目列表的背景颜色,而不是我自己的颜色与的android:listSelector
,因为这就是我'已经已经这样做了。
I want to use the OS item list background color and not my own color with android:listSelector
, because that one I've already do.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@color/blue" />
<item android:drawable="@color/red"/>
</selector>
-----------------------新文件---------------------- ----------
-----------------------new file--------------------------------
<ListView android:id="@+id/list_theme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="@id/contbtn_themelist"
android:stackFromBottom="false"
android:transcriptMode="disabled"/>
-----------------------新文件---------------------- ----------
-----------------------new file--------------------------------
<RelativeLayout android:id="@+id/edit_back"
android:layout_width="80dp"
android:layout_height="77dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:background="@drawable/edit_skin_selector2" >
<ImageView
android:id="@+id/skinEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:scaleType="fitXY"
android:src="@android:drawable/ic_menu_edit"
android:layout_centerInParent="true" />
</RelativeLayout>
编辑: row.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingBottom="5dip"
android:paddingLeft="2dip"
android:paddingRight="2dip"
android:paddingTop="5dip" >
<ImageView
android:id="@+id/itemlist_checkedd"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:src="@drawable/ic_checkitem" />
<ImageView
android:id="@+id/skinpreview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/itemlist_checkedd"
android:scaleType="fitXY" />
<RelativeLayout android:id="@+id/edit_back"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/edit_skin_selector2"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/skinEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@android:drawable/ic_menu_edit"
android:layout_centerInParent="true" />
</RelativeLayout>
<ImageView
android:id="@+id/separator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="5dip"
android:layout_toLeftOf="@id/edit_back"
android:src="@drawable/separator" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="2dip"
android:layout_marginRight="15dip"
android:layout_toLeftOf="@id/separator"
android:layout_toRightOf="@id/skinpreview"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
任何帮助将是巨大的,谢谢你。
Any help will be great, Thanks.
推荐答案
我遇到过这个问题也解决了我这里使用tecnique:
I encountered this issue too, I solved it using the tecnique here:
http://android.cyrilmottier.com/?p=525
看段落不要preSS一切!
Look at the paragraph "Don't press everything!"
这篇关于设置与选择ImageView的背景问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!