android 工作室相对布局
android studio relativelayout
Android 工作室和 Java 的新手。我正在寻找使用 relativelayout 来产生这个:-
Layout required
由于某种原因无法上班。如果布局发生变化,即向右旋转 90 度。这使顶部的图像及其下方的四个按钮起作用。但是用右边的按钮无法得到左边的图片
请帮忙。
使用 LinearLayout 比 Relative 更容易生成布局,如下所示:
<?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>
您可以使用 LinearLayout 而不是 relativelayout。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="button 1" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="button 2" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="button 3" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="button 4" />
</LinearLayout>
</LinearLayout>
Android 工作室和 Java 的新手。我正在寻找使用 relativelayout 来产生这个:- Layout required
由于某种原因无法上班。如果布局发生变化,即向右旋转 90 度。这使顶部的图像及其下方的四个按钮起作用。但是用右边的按钮无法得到左边的图片
请帮忙。
使用 LinearLayout 比 Relative 更容易生成布局,如下所示:
<?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>
您可以使用 LinearLayout 而不是 relativelayout。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="button 1" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="button 2" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="button 3" />
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="button 4" />
</LinearLayout>
</LinearLayout>