嗨我已經創建了一個相對佈局。並將imageview對齊到relativelayout的右側。我使用選擇器設置了relativelayout的背景。如果我選擇thye relativelayout它的顏色將是綠色,否則它的顏色將是白色。現在我想根據scrollview的選擇來設置圖像。如果scrollview被選中,那麼我想顯示imge1,如果沒有,那麼我想顯示image2。我怎樣才能做到這一點?什麼是最好的方式來設置圖像imageview
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>
感謝 蘇尼爾
我試過了。它也適用於我 –