Android Studio 和 Java 的新手。我正在尋找使用相對布局來產生這個: - 需要布局
由于某種原因無法上班。如果布局發生變化,即向右旋轉 90 度。這使頂部的影像及其下方的四個按鈕起作用。但是無法通過右側的按鈕獲取左側的影像。
請任何幫助。
uj5u.com熱心網友回復:
使用 LinearLayout 比使用 RelativeLayout 更容易生成該布局,如下所示:
<?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"
tools:context=".MainActivity">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:weightSum="2">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="20dp"
android:layout_weight="1">
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:text="Image"
android:layout_weight="1">
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="4"
android:padding="20dp">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"></Button>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"></Button>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"></Button>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1"></Button>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/382623.html
下一篇:活動嵌入與片段,何時使用?
