2011-05-26 28 views
3

之前在射擊:選擇反應慢 - 有時不是所有的首發我有這樣的選擇定義的下一個活動

<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)事件慢。

有什麼我可以做的,以確保選擇不是「laggy」?

回答

0

你的意思是比典型的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" 
    /> 
+0

有趣的想法,我會盡快嘗試... – 2011-05-26 19:41:15

+0

你建議的方法似乎有同樣的反應速度,我已經得到。我仍然可以推得很快,UI不會反應,但ACTION_UP事件已經觸發。 – 2011-05-26 20:23:04

+0

我會將你的回答標記爲答案,因爲它似乎不太可能得到更多答案 – 2011-05-26 22:34:00

2

我有同樣的問題。在模擬器中它甚至不改變按鈕的顏色。這是由「onTouch」造成的。如果您使用onClickListener而不是onTouchListener,它將按預期做出反應。

,我可以不使用任何多點觸控能力,看到那麼WY不使用的onClick和擺脫

if (actionPerformed == MotionEvent.ACTION_UP) 
+0

好點,我會給你一個鏡頭。謝謝 !! – 2011-12-16 09:23:46

5

嘗試設置您的視圖,OnTouchListener編程壓:

@Override 
public boolean onTouch(View v, MotionEvent event) { 
    switch (event.getActionMasked()) { 
     case MotionEvent.ACTION_DOWN: 
      button.setPressed(true); 
      break; 
     case MotionEvent.ACTION_UP: 
      // optional, should work without next line 
      // button.setPressed(false); 
      break; 
    } 

    return false; 
} 
+0

太棒了,工作!這種延遲令我瘋狂。 – MScott 2017-10-02 13:35:20

相關問題