Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Layout: position element below lowest view

I've attached a picture to better illustrate what I'm going for.

I have two LinearLayouts positioned side by side. Both are able to expand vertically, using wrap_content. I would like to position another container (HorizontalScrollView) below whichever one has the greater height. It's currently set to go below the right-most column, as generally it is taller, but in some cases the ScrollView will cover up the content in the left-most column. Is there a way to set this in the .xml file or will I need to resort to setting this in my onCreate method?

Example screen

like image 315
Taka Avatar asked Oct 13 '22 17:10

Taka


2 Answers

You can wrap together the two LinearLayouts in another Linear or Relative layout, something like that(just change the properties for the original 3 layouts as you have/need them) :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/parent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>  
<RelativeLayout
android:id="@+id/frame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<LinearLayout
android:id="@+id/linearLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/linearRight"
>
</LinearLayout>
<LinearLayout
android:id="@+id/linearRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
>
</LinearLayout>
</RelativeLayout>
<ScrollView
android:id="@+id/scroll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/frame"
android:layout_alignParentLeft="true"
>
</ScrollView>
</RelativeLayout>
like image 85
Adinia Avatar answered Oct 20 '22 10:10

Adinia


I would like to position another container (HorizontalScrollView) below whichever one has the greater height.

You have to set it programmatically in the onConfigurationChanged method. So that it can work properly after the device's orientation changes.

like image 42
Mudassir Avatar answered Oct 20 '22 09:10

Mudassir