我正在创建显示在其他应用程序之上的 Android 应用程序
我需要包含两个充满按钮的居中栏(线性布局)的布局,我需要这些栏之间的空间,以便用户可以单击覆盖层下方的应用程序。我怎样才能实现这个目标?
焦点,可点击设置为真或假的空间和视图
和
ConstrainLayout 组合
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>