掌托在父母身上休息时如何点击孩子

时间:2018-03-20 09:14:44

标签: android

目前,当手掌停留在屏幕上时,我无法点击按钮。即使手掌停留在屏幕上也能触摸是/否按钮。请查看下面的图像以获取更多信息。enter image description here

我的活动代码::覆盖onTouch方法的是/否按钮在手掌休息和触摸按钮时不调用

    no_btn = (Button) findViewById(R.id.no_btn);
    yes_btn = (Button) findViewById(R.id.yes_btn);
    txt = (TextView) findViewById(R.id.txt);

    bg = (LinearLayout) findViewById(R.id.root);
    views_parent = (LinearLayout) findViewById(R.id.root1);

    //views_parent.setFocusable(true);
    views_parent.setFocusableInTouchMode(true);
    bg.setFocusableInTouchMode(false);

    bg.setOnTouchListener(new View.OnTouchListener(){

        @Override
        public boolean onTouch(View v, MotionEvent arg1) {
            return true;
        }

    });
    yes_btn.setId(1);
    no_btn.setId(0);

    no_btn.setOnTouchListener(this);
    yes_btn.setOnTouchListener(this);

 @Override
public boolean onTouch(View v, MotionEvent event) {
    Log.d("child onTouch>>>","onTouch>>>2>>"+v.getId());
    if (v.getId() == 0)
    {
        isTouchable = false;
    }else if (v.getId() == 1)
    {
        isTouchable = false;
    }

    return false;
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/root"
tools:context="com.example.build.multitouch.MainActivity">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:id="@+id/txt"/>
<LinearLayout
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:orientation="vertical"
    android:background="@color/colorPrimary"
    android:id="@+id/root1">
    <Button
        android:id="@+id/no_btn"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_weight="0"
        android:text="no"
        android:textColor="#fff"
        android:textStyle="bold" />
    <Button
        android:id="@+id/yes_btn"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_weight="0"
        android:text="yes"
        android:textColor="#fff"
        android:textStyle="bold" />
</LinearLayout>
</LinearLayout>

0 个答案:

没有答案