简体   繁体   中英

Android Layout: position element below lowest view

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

I have two LinearLayout s 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?

示例屏幕

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM