Не работает onTouchEvent в landscape

Рейтинг: 0Ответов: 0Опубликовано: 17.04.2023

У меня есть activity:

    public class MainActivity2 extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        TextView txt = (TextView) findViewById(R.id.skip);

        txt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity2.this, REG.class);
                startActivity(intent);
            }
        });
    }

    public boolean onTouchEvent(MotionEvent me){
        if (me.getAction()==MotionEvent.ACTION_DOWN){
            Intent intent = new Intent(MainActivity2.this, MainActivity3.class);
            startActivity(intent);
        }
        return false;
    }

}

В нем есть и кнопка, которая ведет в другую активити, и OnTouchEvent, который тоже ведет в другую активити, отличную от кнопки.

В вертикальной ориентации все работает нормально, но если перевернуть телефон на 90 градусов, OnTouchEvent не реагирует на нажатие по экрану, хотя кнопка реагирует.

Я пробовал использовать:

 @Override
public void onUserInteraction(){
    super.onUserInteraction();
    Intent intent = new Intent(MainActivity2.this, MainActivity3.class);
    startActivity(intent);
}

но он забирает все пространство экрана и кнопка не работает, хотя в альбомной ориетации касание считывается.

Вопрос: почему OnTouchEvent не работает в альбомной ориентации?

Также прикладываю мою директорию res:

Один файл для вертикальной ориентации друго для горизонтальной

Один файл для вертикальной ориентации, другой для горизонтальной.

Мой файл разметки:

<ScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:orientation="horizontal">


        <TextView
            android:id="@+id/skip"
            android:paddingStart="13dp"
            android:paddingTop="20dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textColor="#73A6FD"
            android:textSize="15dp"
            android:text="Пропустить"
            />


        <ImageView
            android:paddingStart="150dp"
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/rect" />
    </LinearLayout>
    <LinearLayout
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:orientation="vertical">


        <TextView
            android:paddingStart="150dp"
            android:paddingTop="80dp"
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:textColor="#26BE02"
            android:text="Анализы" />

        <TextView
            android:id="@+id/textView4"
            android:paddingTop="40dp"
            android:paddingStart="90dp"
            android:textColor="#929295"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Эксперсс сбор и получение проб" />

        <ImageView
            android:id="@+id/imageView5"
            android:paddingTop="50dp"
            android:paddingLeft="-20dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/circle1" />

        <ImageView
            android:id="@+id/imageView6"
            android:paddingTop="70dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:srcCompat="@drawable/colbi" />

    </LinearLayout>

</LinearLayout>
</ScrollView>
</androidx.appcompat.widget.LinearLayoutCompat>

Ответы

Ответов пока нет.