gpt4 book ai didi

android - 在 Android 的 Horizo​​ntal ListView 中突出显示所选图像,它将保持选中状态,直到未单击另一个图像

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:40:47 25 4
gpt4 key购买 nike

我正在使用 HorizantalListView 但是当我点击列表的任何元素时我想显示它被选中并且它应该保持选中状态直到另一个图像没有被点击如何可能请帮助我。

enter image description here

最佳答案

将其设为切换按钮而不是 imageView。然后在 xml 上创建一个选择器,其中包含您希望在每个对应状态上使用的各种图像。 (我现在不确定是否可以使用 imageView 完成同样的操作,这就是我告诉您使用切换按钮的原因)。

<?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/button_pressed"/>
<item android:state_pressed="false"
android:drawable="@drawable/button_rested"/>
<item android:state_enabled="false"
android:drawable="@drawable/button_disabled"/>
</selector>

在布局上

<ToggleButton android:id="@+id/image" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:background="@null" android:gravity="center_horizontal"
android:src="@drawable/button_selector"/>

关于android - 在 Android 的 Horizo​​ntal ListView 中突出显示所选图像,它将保持选中状态,直到未单击另一个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11114818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com