当ImageView变为"true“时,我希望更改boolean。在这种情况下,我希望从“普通星”更改为“黄星”,以防用户需要某种体验。实际上,我有一个使用ImageButton的类似代码。这会在按下按钮时更改图像,但随后会返回到原始图像。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/star_normal"
android:state_pressed="true" />
<item android:drawable="@drawable/star_yellow" />
</selector>和
<ImageButton
android:layout_width="@dimen/_48sdp"
android:layout_height="@dimen/_48sdp"
android:id="@+id/star"
android:layout_weight="1"
android:layout_marginLeft="@dimen/_15sdp"
app:srcCompat="@drawable/star/>如何在布局保存位置不丢失格式的情况下替换ImageView?不能使用按钮,用户不能自行更改图片。
发布于 2017-01-10 16:05:03
我不喜欢选择器,所以我会这样编程:
if (boolean){
imageView.setImageResource(R.drawable.star_yellow);
}要避免调整大小,请指定ImageView xml,如下所示
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/img"
android:src="@drawable/star_normal"
android:maxHeight="48dp"
android:maxWidth="48dp"/>https://stackoverflow.com/questions/41563466
复制相似问题