2016-11-19 3 views
0

See problem in photo안드로이드 버튼 해제 내가 조각에 MotionEvent.ACTION_DOWN에 누를 버튼을 설정하는 선택 및 터치 리스너를 사용하고

를 눌렀습니다. 그러나 상황에 맞는 메뉴는 버튼을 조각 내부되지 pressed.This onTouch 방법이 될 호출 할 때 : 버튼 위치

@Override 
public boolean onTouch(View view, MotionEvent motionEvent) { 
    if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { 
     switch (view.getId()) { 
      case R.id.buttonRow: 
       if (!buttonRow.isPressed()) { 
        buttonRow.setPressed(true); 
        buttonGrid.setPressed(false); 
        setLinearManager(); 
       } 
       break; 
      case R.id.buttonGrid: 
       if (!buttonGrid.isPressed()) { 
        buttonGrid.setPressed(true); 
        buttonRow.setPressed(false); 
        setGridManager(); 
       } 
       break; 
     } 
    } 
    return true; 
} 

조각의 XML :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.example.boss.lesson5.fragments.RecyclerViewFragment"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentTop="true" 
    android:orientation="horizontal"> 

    <ImageButton 
     android:id="@+id/buttonRow" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:layout_weight="1" 
     android:adjustViewBounds="true" 
     android:background="@drawable/button_effect" 
     android:padding="15dp" 
     android:scaleType="centerInside" 
     android:src="@drawable/row" /> 

    <ImageButton 
     android:id="@+id/buttonGrid" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:layout_weight="1" 
     android:adjustViewBounds="true" 
     android:background="@drawable/button_effect" 
     android:padding="15dp" 
     android:scaleType="centerInside" 
     android:src="@drawable/grid" /> 
</LinearLayout> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recycler" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_marginTop="60dp" /> 

답변

1

이 모델로 작업하려고 :

myBtn.setOnTouchListener(new View.OnTouchListener(){ 
      @Override 
      public boolean onTouch(View v, MotionEvent event){ 
       if(event.getAction() == MotionEvent.ACTION_UP){ 

        //do stuff 
       } 
       else if(event.getAction() == MotionEvent.ACTION_DOWN){ 
        //do stuff 
       } 
       else if(event.getAction() == MotionEvent.ACTION_CANCEL){ 
        //do stuff 
       } 
      return true; 
      } 
     }); 
+0

상황에 맞는 메뉴를 클릭해도 MotionEvent가 호출되지 않았습니다. –

관련 문제