单击时抬起LinearLayout

时间:2017-06-06 18:33:19

标签: android material-design elevation

public static LocalResourceName =>Resources.LocalResourceName; 目录中,我有lift_on_touch.xml文件,该文件应在点击时提升线性布局(按住或按住,只需短点击)。文件本身

res/animator

但是当我将layoutListAnimator应用到布局xml中的线性布局时,就像这个<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <objectAnimator android:duration="@android:integer/config_shortAnimTime" android:propertyName="elevation" android:valueTo="6dp" android:valueType="floatType" /> </item> <item> <objectAnimator android:duration="@android:integer/config_shortAnimTime" android:propertyName="elevation" android:valueTo="2dp" android:valueType="floatType" /> </item> </selector> 一样,当我按下并按住我的线性布局但不是时,它只能工作(即提升)它。我的线性布局中也有android:stateListAnimator="@animator/lift_on_touch"

问题:如何解除线性布局点击

1 个答案:

答案 0 :(得分:0)

  

我认为您应该使用onTouchListner()代替onClickListner   在这里你可以通过使用获得Hold和unHold of View的事件   下面的代码

linearLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int action = MotionEventCompat.getActionMasked(event);

                switch(action) {
                    case (MotionEvent.ACTION_DOWN) :
                        Log.d(DEBUG_TAG, "Action was DOWN");
                        // Hold Event will invoke continues 
                        return true;
                    case (MotionEvent.ACTION_MOVE) :
                        Log.d(DEBUG_TAG,"Action was MOVE");
                        return true;
                    case (MotionEvent.ACTION_UP) :
                        Log.d(DEBUG_TAG,"Action was UP");
                        // here unhold event will invoke 
                        return true;
                    case (MotionEvent.ACTION_CANCEL) :
                        Log.d(DEBUG_TAG,"Action was CANCEL");
                        return true;
                    case (MotionEvent.ACTION_OUTSIDE) :
                        Log.d(DEBUG_TAG,"Movement occurred outside bounds " +
                                "of current screen element");
                        return true;

                }
                return false;
            }
        });