Beniamino_Baggins Beniamino_Baggins - 4 months ago 46
Android Question

Position ScrollView below LinearLayout inside RelativeLayout

I'm creating a scrollable menu (ScrollView) with a close button (LinearLayout) that stays at the top of the screen.

My full screen is a RelativeLayout - that Has a LinearLayout (close button) and then a ScrollView (menu) inside it:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/DashboardView_Root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/DashboardView_menuHeaderContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/DashboardView_barContainer"
android:layout_alignBottom="@+id/DashboardView_barContainer"
android:orientation="horizontal">
<ImageView
android:id="@+id/DashboardView_menuBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:paddingLeft="@dimen/layoutPaddingExtra"
android:paddingTop="@dimen/layoutPaddingExtra"
android:paddingRight="@dimen/layoutPaddingExtra"
android:paddingBottom="@dimen/layoutPaddingLess"
android:contentDescription="Menu"
android:layout_gravity="bottom|center_vertical" />
<Iag.TextView
android:id="@+id/DashboardView_menuHeading"
style="@style/Text.H3.Light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/layoutPadding"
android:paddingTop="@dimen/layoutPaddingExtra"
android:paddingRight="@dimen/layoutPaddingExtra"
android:paddingBottom="@dimen/layoutPaddingExtra"
android:layout_gravity="bottom" />
</LinearLayout>
<Scrollview
android:id="@+id/DashboardView_menuContainer"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:fillViewport="true" />
</RelativeLayout>


All looks perfect except that the Scrollview goes up too high, underneath the close button. I want the ScrollView menu to stop at the bottom of the close button (frameLayout).

enter image description here

How do I stop the menu from starting in the same place as the close button (the top of the screen)?

EDIT: Sorry, I said the close button was a FrameLayout Initially but it is a LinearLayout. See code axml above.

Here is the full code for the whole page - the menu just pops out over top the rest of the screen if the user clicks the menu icon:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/DashboardView_Root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/DashboardView_contentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/DashboardView_downBtn"
android:layout_below="@+id/DashboardView_barContainer" />
<ImageView
android:id="@+id/DashboardView_downBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="@dimen/layoutPadding"
android:paddingBottom="@dimen/layoutPaddingExtra"
android:paddingLeft="@dimen/layoutPaddingExtra"
android:paddingRight="@dimen/layoutPaddingExtra"
android:clickable="true"
android:focusable="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<FrameLayout
android:id="@+id/DashboardView_barContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/DashboardView_upBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ab_logo"
android:paddingLeft="@dimen/layoutPaddingExtra"
android:paddingTop="@dimen/layoutPaddingExtra"
android:paddingRight="@dimen/layoutPaddingExtra"
android:paddingBottom="@dimen/layoutPaddingLess"
android:contentDescription="Up"
android:layout_gravity="center_horizontal" />
<ImageView
android:id="@+id/DashboardView_helpBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:src="@drawable/ab_help"
android:paddingLeft="@dimen/layoutPaddingExtra"
android:paddingTop="@dimen/layoutPaddingExtra"
android:paddingRight="@dimen/layoutPaddingExtra"
android:paddingBottom="@dimen/layoutPaddingLess"
android:contentDescription="Help"
android:layout_gravity="right" />
</FrameLayout>
<LinearLayout
android:id="@+id/DashboardView_menuHeaderContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/DashboardView_barContainer"
android:layout_alignBottom="@+id/DashboardView_barContainer"
android:orientation="horizontal">
<ImageView
android:id="@+id/DashboardView_menuBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:paddingLeft="@dimen/layoutPaddingExtra"
android:paddingTop="@dimen/layoutPaddingExtra"
android:paddingRight="@dimen/layoutPaddingExtra"
android:paddingBottom="@dimen/layoutPaddingLess"
android:contentDescription="Menu"
android:layout_gravity="bottom|center_vertical" />
<Iag.TextView
android:id="@+id/DashboardView_menuHeading"
style="@style/Text.H3.Light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/layoutPadding"
android:paddingTop="@dimen/layoutPaddingExtra"
android:paddingRight="@dimen/layoutPaddingExtra"
android:paddingBottom="@dimen/layoutPaddingExtra"
android:layout_gravity="bottom" />
</LinearLayout>
<Scrollview
android:id="@+id/DashboardView_menuContainer"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:fillViewport="true" />
</RelativeLayout>

Answer

So in your case, use android:layout_below to position it below your button. In relative layouts, this kind of attribute is always available.