Ali Behzadian Nejad
Ali Behzadian Nejad

Reputation: 9044

Arrange a scroll view above a linear layout without overlaps

I need to have a scroll view above a horizontal linear layout. My root layout is relative layout (but I can change it based on your solution).

Look at this:

// +-----------+
// |           |
// |    A      |
// |           |
// +-----------+
// |    B      |
// +-----------+

B is a linear menu at the bottom of layout and aligned horizontally center.
A contains some options that may overlaps B area.

my layout xml (with simplification) is something like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/view1"
            android:layout_above="@+id/bottom_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:orientation="vertical"
            android:visibility="invisible" 
            android:layout_weight="1">
        </LinearLayout>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/view2"
            android:layout_above="@+id/bottom_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:orientation="vertical"
            android:visibility="invisible" 
            android:layout_weight="1">
        </LinearLayout>
        <LinearLayout
            android:id="@+id/bottom_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_margin="5dp"
            android:orientation="horizontal"
            android:padding="5dp" >
        </LinearLayout>
</RelativeLayout> 

What should I do to avoid this?

Upvotes: 0

Views: 1189

Answers (1)

Ali Behzadian Nejad
Ali Behzadian Nejad

Reputation: 9044

After dealing with the problem, I figured out that I should use margins!

The solution is:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/acroll1"
    android:layout_height="wrap_content" 
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:layout_marginBottom="90dp">

90dp is the actual size of B area with margins.

I know that this is not a real solution but it works fine for me and this may help someone else.

Upvotes: 2

Related Questions