简体   繁体   中英

Android RelativeLayout issue

I've got a RelativeLayout with two nested RelativeLayouts. I want first RL to stay on top and second to be scrollable, but this does not work.

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <RelativeLayout
    android:id="@+id/relativeTop"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <!--Buttons-->
  </RelativeLayout>
  <ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content">
      <!--Lots of nested RelatiLayouts with Views-->
    </RelativeLayout> 
  </ScrollView>
</RelativeLayout>

There is an xml attribute you need to know for that android:layout_below

<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <RelativeLayout
    android:id="@+id/relativeTop"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <!--Buttons-->
  </RelativeLayout>
  <ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/relativeTop"> <!-- here it goes! -->
    <RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="wrap_content">
      <!--Lots of nested RelatiLayouts with Views-->
    </RelativeLayout> 
  </ScrollView>
</RelativeLayout>

An alternative is LinearLayout which works great for there layouts as it can "divide" your layout into the two parts...

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