I play with android layouts and try to do a simple QA test, but I canβt set up the layout correctly. I just donβt know how to level these things, and after a few hours of battle I need a 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 always be at the bottom, and the question should always be at the top. But when the text is long, the view should stretch inside the scroll.
EDIT:
I found a path without a relative layout. I don't know if this is a bug or function, but this layout scales as 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>
source share