布局元素之间的可点击空间

问题描述 投票:0回答:1

我正在创建显示在其他应用程序之上的 Android 应用程序

我需要包含两个充满按钮的居中栏(线性布局)的布局,我需要这些栏之间的空间,以便用户可以单击覆盖层下方的应用程序。我怎样才能实现这个目标?

焦点,可点击设置为真或假的空间和视图

ConstrainLayout 组合

android xml layout frontend
1个回答
0
投票
public void onSpacerClicked(View view) {
// Handle the click event for the spacer
// You can put your logic here

}

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp">

    <!-- Top Bar -->
    <LinearLayout
        android:id="@+id/topBar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        <!-- Buttons for the top bar -->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 1"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 2"/>
        <!-- Add more buttons as needed -->

    </LinearLayout>

    <!-- Clickable Space -->
    <View
        android:id="@+id/clickableSpace"
        android:layout_width="0dp"
        android:layout_height="16dp"
        android:layout_marginTop="8dp"
        android:background="@android:color/transparent"
        app:layout_constraintTop_toBottomOf="@id/topBar"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:clickable="true"
        android:focusable="true"
        android:onClick="onSpacerClicked"/>

    <!-- Bottom Bar -->
    <LinearLayout
        android:id="@+id/bottomBar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_constraintTop_toBottomOf="@id/clickableSpace"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent">

        <!-- Buttons for the bottom bar -->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 3"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 4"/>
        <!-- Add more buttons as needed -->

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

© www.soinside.com 2019 - 2024. All rights reserved.