Android在不应该点击的情况下检测

Android在不应该点击的情况下检测,第1张

概述我有一个图像按钮和关联的单击处理程序.当我为按钮制作动画(使用平移动画)时,该按钮显然会更改其在屏幕上的位置.但是有一个问题:当我触摸初始按钮位置而非当前位置时,Android会检测点击.如何使Android尊重按钮的实际位置?fragment_main.xml<RelativeLayoutxmlns:android="h

我有一个图像按钮和关联的单击处理程序.

当我为按钮制作动画(使用平移动画)时,该按钮显然会更改其在屏幕上的位置.

但是有一个问题:当我触摸初始按钮位置而非当前位置时,Android会检测到点击.

如何使AndroID尊重按钮的实际位置?

fragment_main.xml

<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"                androID:layout_wIDth="match_parent"                androID:layout_height="match_parent">    <Imagebutton        androID:ID="@+ID/addbutton"        androID:src="@androID:drawable/ic_input_add"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:onClick="plusbuttonClick"/></relativeLayout>

MainActivity.java

public class MainActivity extends ActionBaractivity{    public voID plusbuttonClick(VIEw v)    {        Toast.makeText(this, "Clicked!", Toast.LENGTH_SHORT).show();        animatebutton(R.ID.addbutton, R.anim.anim_move);    }    private voID animatebutton(int buttonID, int animationID)    {        VIEw button = findVIEwByID(buttonID);        AnimationSet animationSet = (AnimationSet)AnimationUtils.loadAnimation(this, animationID);        animationSet.setAnimationListener(getStartingbuttonsListener(button));        button.setVisibility(VIEw.VISIBLE);        button.startAnimation(animationSet);    }    private Animation.AnimationListener getStartingbuttonsListener(final VIEw v)    {        return new Animation.AnimationListener()        {            @OverrIDe            public voID onAnimationEnd(Animation arg0)            {                v.setVisibility(VIEw.GONE);            }        };    }}

anim_move.xml

<?xml version="1.0" enCoding="utf-8"?><set xmlns:androID="http://schemas.androID.com/apk/res/androID"     androID:shareInterpolator="true"     androID:fillAfter="true"     androID:duration="1000">    <translate        androID:fromXDelta="0"        androID:toXDelta="180"        androID:fromYDelta="0"        androID:toYDelta="0"/></set>

解决方法:

我在这里有一个类似的问题:Button moves to different part of screen but can only press it at its initial spot?

动画是对像素进行动画处理,而不是对小部件的触摸区域进行动画处理.
您还需要为属性设置动画:https://developer.android.com/guide/topics/graphics/prop-animation.html

总结

以上是内存溢出为你收集整理的Android在不应该点击的情况下检测全部内容,希望文章能够帮你解决Android在不应该点击的情况下检测所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1088100.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存