I'm playing with android layouts and trying to make a simple QA test, but I can't get the layout right. I just have no idea how to align those things and after few hours of fight I need little help.
Here is what I want:
And what I get:
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<RelativeLayout
android:id="@+id/nodeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="TextView"
android:textSize="18dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/radioAnswersGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</RadioGroup>
<LinearLayout
android:id="@+id/questionsNavigationGroup"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<Button
android:id="@+id/buttonPreviousQuestion"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1"
android:background="@drawable/fancy_button"
android:gravity="center|center_vertical"
android:onClick="onPreviousQuestionButtonClick"
android:shadowColor="#fff"
android:shadowRadius="3"
android:text="Back"
android:textColor="#432f11"
android:textSize="24dp" />
<Button
android:id="@+id/buttonNextQuestion"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1"
android:background="@drawable/fancy_button"
android:gravity="center|center_vertical"
android:onClick="onNextQuestionButtonClick"
android:shadowColor="#fff"
android:shadowRadius="3"
android:text="Next"
android:textColor="#432f11"
android:textSize="24dp" />
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
Answers and buttons should be always on bottom, and question should be always on top. But when text is long, the view should stretch inside scroll view.
I found the way without relative layout. I don't know if this is a bug or feature but this layout scales like I want.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textQuestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="top" />
<LinearLayout
android:id="@+id/bottomStuff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="bottom"
android:orientation="vertical" >
<RadioGroup
android:id="@+id/radioAnswersGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</RadioGroup>
<LinearLayout
android:id="@+id/questionsNavigationGroup"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<Button
android:id="@+id/buttonPreviousQuestion"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1" />
<Button
android:id="@+id/buttonNextQuestion"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_weight="1" />
<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
I think you should use this:
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With