嗨,我创造了一个相对的布局。并将图像视图与相对输出的右边对齐。我使用选择器设置了相对输出的背景。如果我选择这个,它的颜色将是绿色的,否则它的颜色将是白色的。现在,我想根据滚动视图的选择来设置图像。如果选择了滚动视图,那么我想要显示imge1,如果不是,那么我要显示image2。我怎样才能做到这一点?
main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_right"
android:layout_alignParentRight="true" />
</RelativeLayout>selector.xml
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/grbk" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/grbk" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/grbk" />
<item
android:drawable="@drawable/whbk" />
</selector>谢谢苏尼尔

发布于 2011-06-28 12:46:19
以和背景一样的方式。您应该添加android:duplicateParentState="true"
<ImageView
android:duplicateParentState="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_selector"
android:layout_alignParentRight="true" />https://stackoverflow.com/questions/6506249
复制相似问题