'Home' 和 'Btn3' 之間的空間應該在布局的中線,但我不知道如何做到這一點。
我的布局看起來像這樣

正如您所看到的,我在兩個元素之間有一個鏈(按鈕位于 LinearLayout 中。)您可以看到按鈕在父元素中沒有垂直居中。
'Home' 和 'Btn3' 之間的空間應該在布局的中線,但我不知道如何做到這一點。
顯然我可以將按鈕布局限制在父級的頂部和底部,但是當布局旋轉并變小時,我們會得到這樣的重疊。

我的 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff303030"
tools:ignore="HardcodedText">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.Guideline
android:id="@ id/guide_logo_end"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.98" />
<androidx.constraintlayout.widget.Guideline
android:id="@ id/guide_logo_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.02" />
<LinearLayout
android:id="@ id/logo_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="@id/button_layout"
app:layout_constraintEnd_toEndOf="@id/guide_logo_end"
app:layout_constraintTop_toTopOf="@id/guide_logo_top"
app:layout_constraintVertical_chainStyle="spread_inside">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo_small" />
<TextView
android:id="@ id/version_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20px"
android:text="virtual console"
android:textColor="#ffffff"
android:textSize="34px" />
<TextView
android:id="@ id/version_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10px"
android:textColor="#909090"
android:textSize="28px"
tools:text="x.x.xx.xxxx" />
</LinearLayout>
<LinearLayout
android:id="@ id/button_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@ id/enable_disable_btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/full_day_selector"
android:gravity="center"
android:text="Btn1"
android:textSize="50sp" />
<Button
android:id="@ id/demo_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32px"
android:background="@drawable/full_day_selector"
android:gravity="center"
android:text="Home"
android:textSize="50sp" />
<Button
android:id="@ id/demo_btn3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32px"
android:background="@drawable/full_day_selector"
android:gravity="center"
android:text="Btn3"
android:textSize="50sp" />
<Button
android:id="@ id/demo_admin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32px"
android:background="@drawable/full_day_selector"
android:gravity="center"
android:text="Admin"
android:textSize="50sp" />
</LinearLayout>
<Space
android:id="@ id/space_bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/button_layout" />
</androidx.constraintlayout.widget.ConstraintLayout>
uj5u.com熱心網友回復:
洗掉 logo_layout 的 linearLayout 并嘗試使用約束布局選項創建布局,用 scrollView 替換相對布局,創建垂直鏈并使用其中一種模式,您也可以為小部件設定 android:minHeight="...dp"

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/351756.html
標籤:安卓 安卓布局 android-constraintlayout
上一篇:如何在貝寶付款中完成待處理的交易
