【发布时间】:2019-01-14 20:35:17
【问题描述】:
我必须使用LinearLayout 在 Android Studio 中制作这个小应用类型的东西。
说明说我们必须使用vertical 方向作为根标签(顶部的文本显示“这是我的小部件”),然后每行使用horizontal 方向。我唯一的问题是如何将东西放在不同的行上?
它应该看起来像:
第 1 行:“这是我的小部件”(垂直方向)
第 2 行: BUTTON IMAGEBUTTON
第 3 行: CHECKBOX SWITCH
我的问题是,当我创建一个新的嵌套 LinearLayout 时,它会显示在第 2 行。如何使用horizontal 方向创建第 3 行?我尝试用vertical 方向放置一个空的LinearLayout 东西,以便将两行分开,但这不起作用。如何使CheckBox 和开关显示在按钮下方?我必须使用LinearLayout,并且方向必须是水平的。这是我的代码:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_message"
android:textSize="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:gravity="fill"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:text="@string/ButtonText" />
<ImageButton
android:gravity="fill"
android:layout_weight="1"
android:layout_height="match_parent"
android:layout_width="200dp"
android:src="@drawable/flag"
android:scaleType="centerInside"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Switch
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
【问题讨论】:
标签: android xml android-studio-3.0