android–Selector反应缓慢 – 有时在开始下一个活动之前根本不会开火

android–Selector反应缓慢 – 有时在开始下一个活动之前根本不会开火,第1张

概述我定义了这个Selector:<selectorxmlns:android="http://schemas.android.com/apkes/android"><!--PRESSED--><itemandroid:state_pressed="true"android:drawable="@drawable/backarrow_blueshiny"/&g

我定义了这个Selector:

<selector xmlns:androID="http://schemas.androID.com/apk/res/androID">    <!-- pressed -->    <item androID:state_pressed="true"          androID:drawable="@drawable/backarrow_blueshiny" />    <!-- FOCUSED -->     <item androID:state_focused="true"          androID:drawable="@drawable/backarrow_blackshiny" />    <!-- DEFAulT -->    <item androID:drawable="@drawable/backarrow_blackshiny" /></selector>

它与此按钮一起使用:

    <relativeLayout    androID:orIEntation="horizontal"    androID:layout_wIDth="fill_parent"    androID:layout_height="wrap_content"     androID:background="@drawable/bottomborder_glossy">        <!-- BACK -->        <Imagebutton        androID:ID="@+ID/filter_button_back"        androID:layout_wIDth="90dip"         androID:layout_height="wrap_content"         androID:src="@drawable/selector_back_button"        androID:background="#00000000"        androID:layout_alignParentleft="true"        androID:layout_alignParentBottom="true"/>    </relativeLayout>

并且ontouch事件包括:

public boolean ontouch(VIEw v, MotionEvent event){    final int actionPerformed = event.getAction();    final int WidgetID = v.getID();    if (actionPerformed == MotionEvent.ACTION_UP)    {        switch (WidgetID)        {            case R.ID.filter_button_back:            {                this.finish();                break;            }        }    }    return false;}

这个按钮的作用是退出当前活动this.finish()
但是,在我的测试中,按钮并不总是切换到“backarrow_blueshiny” – 即按下非常快.

所以问题是选择器的触发速度比ontouch(MotionEvent.ACTION_UP)事件慢.

有什么我可以做的,以确保选择器不“滞后”?

解决方法:

你的意思是比典型的AndroID选择器行为更懒散吗?根据我的经验,按下按钮之间总会有一点延迟,并且它被选中 – 我认为这是为了避免在你想要滚动时显示触摸事件,但它总是让我感到烦恼.如果它不仅仅是典型的行为,请尝试仅使用一个按钮,将androID:background设置为选择器,而不是将androID:src设置为选择器的Imagebutton.

例如

<button    androID:layout_wIDth="90dip"    androID:layout_height="wrap_content"    androID:background="@drawable/selector_back_button"    androID:layout_alignParentleft="true"    androID:layout_alignParentBottom="true"     />
总结

以上是内存溢出为你收集整理的android – Selector反应缓慢 – 有时在开始下一个活动之前根本不会开火全部内容,希望文章能够帮你解决android – Selector反应缓慢 – 有时在开始下一个活动之前根本不会开火所遇到的程序开发问题。

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

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

原文地址: https://outofmemory.cn/web/1114072.html

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

发表评论

登录后才能评论

评论列表(0条)

保存