Android 在按钮上闪烁图像单击按钮
当我在键盘上工作时,我们知道在任何安卓设备的默认键盘上,当我们点击任何按钮时,按钮上方会闪烁较大的图像,我不知道确切的效果,但我已经尝试使用下面的代码 在myKeyboard.xml中单击的按钮:Android 在按钮上闪烁图像单击按钮,android,image,buttonclick,Android,Image,Buttonclick,当我在键盘上工作时,我们知道在任何安卓设备的默认键盘上,当我们点击任何按钮时,按钮上方会闪烁较大的图像,我不知道确切的效果,但我已经尝试使用下面的代码 在myKeyboard.xml中单击的按钮: <Button android:id="@+id/xBack" android:background="@drawable/back_high"/> 上面的back\u high是我的xml文件 back\u high.xml文件是 <?xml versi
<Button android:id="@+id/xBack"
android:background="@drawable/back_high"/>
上面的back\u high是我的xml文件
back\u high.xml文件是
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/back_click"
android:state_pressed="true" />
<item android:drawable="@drawable/back"
android:state_focused="true" />
<item android:drawable="@drawable/back" />
</selector>
它工作成功,但图像在我单击的同一位置闪烁,但我需要此图像显示在上面的按钮上,就像在android默认键盘上一样。您设置特定按钮的背景,因此,如果希望它显示在按钮上方,请确保使用框架布局作为键盘的总体布局,然后使用一个额外的图像视图,以便在单击按钮时切换位置和资源。你不再需要选择器了 框架布局允许您将多个视图放在彼此的顶部。这: 为什么不以编程方式而不是UI模式进行此操作 有几种,这取决于你所指的闪烁类型。 例如,可以使用alpha动画,并在按钮第一次出现时启动它。当用户单击按钮时,在
OnClickListener
中只需执行clearAnimation()
例如:
public void onCreate(Bundle savedInstanceState) {
final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
animation.setDuration(500); // duration - half a second
animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in
final Button btn = (Button) findViewById(R.id.your_btn);
btn.startAnimation(animation);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View view) {
view.clearAnimation();
}
});
}
另外。@l7colwinters是正确的-您需要一个单独的弹出窗口来显示闪烁的图像。您正在设置同一视图的背景-与您的目的无关。@uval好的,我已经实现了弹出窗口,它对我来说工作正常。但我有一个问题,我需要当前单击视图的坐标,因为我必须在触摸特定按钮时显示单独的图像;因为它在根布局中给了我x坐标,但如果我在同一个视图中单击不同的位置,它会给我不同的坐标,我想这就是你们想要的。您也可以获得触摸视图的位置:好的,我已经实现了弹出窗口,它对我来说工作正常。但我有一个问题,我需要我当前点击视图的坐标,因为我必须在触摸特定按钮时显示单独的图像。