Search code examples
androidandroid-relativelayout

ScrollView inside RelativeLayout doesn't work


I have a LinearLayout and dynamically created elements in it. I need to make it scrollable if its height will be larger than 0.8 of screen's height. I'm trying to do it like that. Where is my mistake?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:id="@+id/layoutContainer" android:orientation="vertical"
        android:baselineAligned="false" android:weightSum="1">


            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:scrollbars="vertical"
                android:layout_weight="0.85" >
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent" android:layout_height="wrap_content"
                android:id="@+id/alarmsLayout" android:orientation="vertical"
                android:layout_marginTop="70dp" >
            </LinearLayout>
            </ScrollView>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.15">
            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/addAlarmBtn"
                android:src="@drawable/time"
                android:layout_marginBottom="15dp" />
        </LinearLayout>
    </LinearLayout>

Solution

  • <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/layoutContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="1"
        android:baselineAligned="false"
        android:orientation="vertical" >
    
    
            <ScrollView
                android:layout_weight="0.8" 
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:scrollbars="vertical" >
    
                <LinearLayout
                    android:id="@+id/alarmsLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="70dp"
                    android:orientation="vertical" >
                </LinearLayout>
            </ScrollView>
    
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="0.15" >
    
            <ImageView
                android:id="@+id/addAlarmBtn"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="15dp"
                android:src="@drawable/background_button" />
        </RelativeLayout>
    
    </LinearLayout>