android-layout - Android - 顶部带有按钮的拆分视图
问题描述
我正在尝试在 android 中拆分屏幕并尝试在分隔符顶部覆盖一个按钮
下面是我的 XML 布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:weightSum="2">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ff0000" />
<RelativeLayout
android:background="#00ff00"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="90sp"
android:layout_height="90sp"
app:srcCompat="@drawable/exchange"
android:layout_centerHorizontal="true"
android:layout_marginTop="-45dp"/>
</RelativeLayout>
</LinearLayout>
解决方案
您可以通过以有序方式对齐布局或使用Constraint Layout
.
演示.xml
[![<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/holo_red_light">
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/holo_blue_dark">
</RelativeLayout>
</LinearLayout>
<ImageButton
android:id="@+id/imageButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:srcCompat="@android:drawable/btn_dialog" />
</RelativeLayout>][1]][1]
推荐阅读
- apache - 如何将 https://www.example.com/aaa 重定向到 https://example.com/aaa/
- python - 在不使用任何模块的情况下,在 python 中实现堆栈和队列的最佳方法是什么?
- python - 我尝试将 RK4 实施到 N 体模拟。但是从图中看代码不能正常工作
- join - 如何在主表上加入按天聚合的数据
- do-while - Java Do While 循环不断重复相同的输出
- android - 在android godot游戏中解析包时出现问题
- reactjs - TypeError:使用 Openlayers 和 Jest + Enzyme 时无法读取 null 的属性“setTransform”
- javascript - 使用 webpack 文件加载器加载图像时遇到问题
- azure-data-factory - Azure 数据工厂 - 如何在 Azure SQL 中将字符串 HH:mm 转换为 Time(7) 类型?
- blazor - 找不到 Blazor InputFile IFileListEntry