首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >区分两指旋转和简单抽头

区分两指旋转和简单抽头
EN

Stack Overflow用户
提问于 2017-05-08 10:40:24
回答 1查看 29关注 0票数 0

在我的片段中,我有一个TextView,下面有两个按钮。我需要实现一个OnTouchListener来做两件事:

  1. 当我旋转我的两个手指时,TeXtView会旋转
  2. 当我点击TeXtView时,下面的按钮被调用

现在它不起作用,但我找不到更好的解决办法。

XML:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_centerInParent="true"
    tools:context="com.fjord.yalc.MainActivity"
    android:id="@+id/player_fragment">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <Button
            android:id="@+id/buttonUp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/transparent"/>

        <Button
            android:id="@+id/buttonDown"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@android:color/transparent"/>

    </LinearLayout>

    <com.fjord.yalc.AutoResizeTextView
        android:id="@+id/player"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:maxLines="1"
        android:text="@string/normal_start"
        android:textAppearance="@android:style/TextAppearance.DeviceDefault.DialogWindowTitle"
        android:textColor="@color/colorLightGray"
        android:textSize="300sp"
        android:textStyle="bold"
        android:layout_marginLeft="25dp"
        android:layout_marginRight="25dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true" />


</RelativeLayout>

爪哇:

代码语言:javascript
复制
Btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                player.setText(String.valueOf(++life));
            }
        });

        mRotationDetector = new RotationGestureDetector(this);



        TV.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                int maskedAction = event.getActionMasked();

                switch (maskedAction) {
                    case MotionEvent.ACTION_DOWN: {
                        return false;
                    }
                    case MotionEvent.ACTION_OUTSIDE: {
                        return false;
                    }
                    case MotionEvent.ACTION_MOVE: {
                        mRotationDetector.onTouchEvent(event);
                        break;
                    }
                }
                return true;
            }

        });
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-14 22:52:41

好吧,一周后我找到了答案。我需要使用MotionEvent将我的dispatchTouchEvent分配给按钮的父级。ACTION_POINTER_DOWN用于检查用户是否使用两个手指。现在旋转到mRotationDetector,点击到_TextView播放器下面的按钮的onClickListener_s。

爪哇:

代码语言:javascript
复制
player.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                MotionEvent me = MotionEvent.obtain(event);
                mRotationDetector.onTouchEvent(me);
                switch (event.getActionMasked()){
                    case (MotionEvent.ACTION_DOWN):
                        flag=true;
                        break;
                    case(MotionEvent.ACTION_POINTER_DOWN):
                        flag=false;
                        break;
                }

                buttons.dispatchTouchEvent(event);
                return true;
            }
        });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43845547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档