I have to use LinearLayout
to make this little app type thing in Android Studio.
The instructions say we have to use vertical
orientation for the root tag (and this text at the top says "Here are my widgets") and then horizontal
orientation for each row. My only issue is how to place things on different rows?
It's supposed to look like:
Row 1: "Here are my widgets" (Vert orientation)
Row 2: BUTTON IMAGEBUTTON
Row 3: CHECKBOX SWITCH
My issue is, when I make a new nested LinearLayout
, it shows up on row 2. How do I make a row 3 with horizontal
orientation? I tried putting an empty LinearLayout
thing with vertical
orientation to maybe split the two rows up, but that didn't work. How do I make the CheckBox
and switch show up beneath the buttons? I have to use LinearLayout
, and the orientation has to be horizontal. Here's my code:
<?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>