开发者

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开发者_StackOverflow this in my onCreate method?

Android Layout: position element below lowest view


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜