【问题标题】:Button Pressed Animation be longerButton Pressed Animation 更长
【发布时间】:2013-11-26 23:05:57
【问题描述】:

我有这个按钮 xml,当它被按下时,按下的图像(b)会在返回正常按钮之前显示更长的时间。

这是我的 xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/a" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/b" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/b" />
<item android:drawable="@drawable/a" />

有人对此有想法吗?

为了修复。我用过这个。

closeButton.setOnTouchListener(new View.OnTouchListener() {

        public boolean onTouch(final View v, MotionEvent event) {
            switch(event.getAction())
            {
            case MotionEvent.ACTION_DOWN:
                v.setPressed(true);
                return true;
            case MotionEvent.ACTION_UP:
                v.setPressed(false);
                try {
            Thread.sleep(150);
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        return true;
        }
            return false;  

        }
 });

【问题讨论】:

  • 您的问题是什么?你想让动画更长吗?
  • 解释很差。通过看到这个选择,人们可以理解的是,对于按钮的三种不同状态,有 3 组图像。现在动画是在哪里出现的,你所说的“更长”到底是什么意思,没有信息???

标签: android animation button pressed


【解决方案1】:

您可以使用 exitFadeDuration 为状态更改设置动画

<selector xmlns:android="http://schemas.android.com/apk/res/android"
        android:exitFadeDuration="@android:integer/config_mediumAnimTime">
    <item android:state_activated="true" android:drawable="@android:drawable/list_selector_background_selected" />
    <item android:drawable="@color/transparent" />
</selector>

这将在您的选择器上淡入/淡出状态更改,您可以将时间更改为其他内容。

【讨论】:

    【解决方案2】:

    像这样试试..

    Handler handler=new Handler();
    mybutton.setOnTouchListener(new OnTouchListener() {
    
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                v.setPressed(true);
               handler.postDelayed(new Runnable() {
     @Override
     public void run() {
    v.setPressed(false);
     }
     }, 2000);<-- you can set for how much time the button should be in pressed state..2 seco9nds in this case
                return true;
            }
        });
    

    【讨论】:

    • 但是,此解决方案仅适用于快速按下按钮的情况。如果长按按钮呢?
    • 我编辑了我的问题并为我的问题添加了解决方案。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2019-10-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多