更改图像按钮行为
拥有此选择器 XML 文件:
<?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/z01_pressed" /> <!-- pressed -->
<item android:state_active="true"
android:drawable="@drawable/z01_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/z01_pressed" /> <!-- focused -->
<item android:drawable="@drawable/z01" /> <!-- default -->
</selector>
我可以修改它(或以编程方式)以在 Android 中执行此操作:
当您单击并按住 ImageButton 并将手指移动到另一个 ImageButton 时,另一个会获得效果(按下效果)并且第一个恢复到正常状态。
因此,如果您的屏幕上有多个按钮,并且您在它们上面滑动手指,则当手指位于其上方时,每个按钮都会获得按下效果
这可以在 XML 中完成吗?代码?在 API 4 中?或以上?
这可能吗?
谢谢
Having this selector XML file:
<?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/z01_pressed" /> <!-- pressed -->
<item android:state_active="true"
android:drawable="@drawable/z01_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/z01_pressed" /> <!-- focused -->
<item android:drawable="@drawable/z01" /> <!-- default -->
</selector>
Can I modify it (or have a programmatic way) to do this in Android:
When you click and hold an ImageButton and move you finger to another ImageButton the other one gets the effect (The pressing effect) and the first one returns to its normal state.
So, If you have multiple buttons in your screen and you slide your finger in top of them, each one gets the press effect when the finger is above it
Can this be done in XML? Code? In API 4 ? or above?
Is this even possible?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于那些可能感兴趣的人:
我在 API 级别 4 下找不到解决我的问题的方法。所以,我放弃了!
To those who might be interested:
I couldn't find a solution to my problem under API level 4. So, I gave up !
您可以通过为每个按钮使用 onTouchListener 和 Region 对象来完成此操作。首先,您需要找到每个按钮的大小,以便能够确定区域对象的大小:
编辑:
You can do this by using an onTouchListener and a Region object for each button. First you need to find the size of each button to be able to determine the size of the Region objects:
EDIT: