Android RelativeLayout supports

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:

enter image description here

And what I get:

enter image description here

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> 
+6
source share
9 answers

I think you should use this:

 <ScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="wrap_content" android:fillViewport="true" > 
+2
source

add this line to the TextView element:

 android:layout_above="@+id/radioAnswersGroup" 
+1
source

try it

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/RelativeLayout1" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/scrollView1" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_above="@+id/radioGroup1" android:layout_alignParentRight="true"> <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="wrap_content" android:id="@+id/textView1" android:text="TextView" android:layout_height="wrap_content" /> </LinearLayout> </ScrollView> <RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radioGroup1" android:layout_above="@+id/spinner1" android:layout_alignParentRight="true" android:layout_alignParentLeft="true"> <RadioButton android:layout_width="wrap_content" android:id="@+id/radio0" android:layout_height="wrap_content" android:text="RadioButton" android:checked="true" /> <RadioButton android:layout_width="wrap_content" android:id="@+id/radio1" android:layout_height="wrap_content" android:text="RadioButton" /> <RadioButton android:layout_width="wrap_content" android:id="@+id/radio2" android:layout_height="wrap_content" android:text="RadioButton" /> <RadioButton android:layout_width="wrap_content" android:id="@+id/radio3" android:layout_height="wrap_content" android:text="RadioButton" /> </RadioGroup> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:text="Button" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button2" android:text="Button" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" /> <Spinner android:id="@+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" /> </RelativeLayout> 
0
source

You can try giving LinearLayout lower TextView identifier, for example android:id="@+id/bottomhalf" , and also define android:layout_below="@+id/textQuestion"

Then add android:layout_above="@+id/bottomhalf" to your TextView android:layout_above="@+id/bottomhalf"

0
source

I think the following changes will help solve the problem,

 <ScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="wrap_content" android:fillViewport="true" > 

instead of <

 <ScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" > 

Hope this helps.

0
source

Use the following layout, it displays the result, as you mentioned in the 1st link. Change intervals and drawings. Hope this helps you.

I used the resolution 800X480 in portrait mode to check the output, you need to change the width and height of the layout according to the resolution of your device.

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rootLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="300px" android:fillViewport="true" > <TextView android:id="@+id/textQuestion" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_alignParentTop="true" android:text="TextView" android:textSize="18dp" /> </ScrollView> <RadioGroup android:id="@+id/radioAnswersGroup" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true"> <RadioButton android:layout_width="wrap_content" android:id="@+id/radio0" android:layout_height="wrap_content" android:text="RadioButton" android:checked="true" /> <RadioButton android:layout_width="wrap_content" android:id="@+id/radio1" android:layout_height="wrap_content" android:text="RadioButton" /> <RadioButton android:layout_width="wrap_content" android:id="@+id/radio2" android:layout_height="wrap_content" android:text="RadioButton" /> <RadioButton android:layout_width="wrap_content" android:id="@+id/radio3" android:layout_height="wrap_content" android:text="RadioButton" /> </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: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: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> 
0
source

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> 
0
source

In fact, I was working on a similar project that has some kind of similar requirement. I have both counters, imageviews buttons, etc. On the panel

Please check the xml layout code below and try changing some of its settings to adjust it accordingly.

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="3sp" > <LinearLayout android:id="@+id/linearLayout" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" android:baselineAligned="true" android:orientation="horizontal" > <ScrollView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" > <RelativeLayout android:id="@+id/innerRelativeLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" > <ImageView android:id="@+id/imgStartStop" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginLeft="10dp" android:layout_marginTop="20dp" android:contentDescription="@string/startstop" android:onClick="startstop" android:src="@drawable/start" /> <Button android:id="@+id/btnStatus" android:layout_width="220dp" android:layout_height="75dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginTop="10dp" android:layout_toRightOf="@id/imgStartStop" android:onClick="showStatus" android:text="@string/ontime" /> <ImageView android:id="@+id/imgPushToTalk" android:layout_width="100dp" android:layout_height="100dp" android:layout_below="@id/imgStartStop" android:layout_centerHorizontal="true" android:layout_marginTop="25dp" android:contentDescription="@string/pushtotalk" android:onClick="activatePushtoTalk" android:src="@drawable/pushtotalkidle" /> <TextView android:id="@+id/txtExpectedNumberofPassengers" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/imgPushToTalk" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:text="@string/expectednumberofpassengers" android:textSize="30sp" /> <TextView android:id="@+id/txtNumberofPassengers" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/imgPushToTalk" android:layout_marginTop="5dp" android:layout_toLeftOf="@id/txtExpectedNumberofPassengers" android:text="@string/numberofpassengers" android:textColor="@color/greenText" android:textSize="30sp" /> </RelativeLayout> </ScrollView> <fragment android:id="@+id/mapFragment" android:name="com.google.android.gms.maps.MapFragment" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="3" /> </LinearLayout> <TextView android:id="@+id/txtTickerMessage" android:layout_width="fill_parent" android:layout_height="wrap_content" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:singleLine="true" android:text="@string/tickermessage" android:textAppearance="?android:attr/textAppearanceLarge" /> </LinearLayout> 
0
source

This will work:

 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:id="@+id/linear1"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="text"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:id="@+id/linear2"> <RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radioGroup1"> <RadioButton android:layout_width="wrap_content" android:id="@+id/radio0" android:layout_height="wrap_content" android:text="RadioButton" android:checked="true" /> <RadioButton android:layout_width="wrap_content" android:id="@+id/radio1" android:layout_height="wrap_content" android:text="RadioButton" /> <RadioButton android:layout_width="wrap_content" android:id="@+id/radio2" android:layout_height="wrap_content" android:text="RadioButton" /> <RadioButton android:layout_width="wrap_content" android:id="@+id/radio3" android:layout_height="wrap_content" android:text="RadioButton" /> </RadioGroup> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:id="@+id/linear3"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button1" android:text="Button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button2" android:text="Button" /> <Spinner android:id="@+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout> </ScrollView> 
0
source

Source: https://habr.com/ru/post/903966/


All Articles