Search code examples
androidandroid-scrollviewandroid-relativelayout

Change RelativeLayout To ScrollView


I have created an app that consists of a RelativeLayout. After adding in all the information the RelativeLayout is too small to fit all the information in. I need to be able to scroll up and down using the ScrollView layout. I have tired replacing the word RelativeLayout with ScrollView as well as adding the ScrollView inside the RelativeLayout but then my app crashes. So not sure where to put the ScrollView.

main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:background="@android:color/black"
tools:context=".MainActivity">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true">

<mudasir.com.gifsimages.GIF.GifImageView
    android:id="@+id/GifImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true" />

<mudasir.com.gifsimages.GIF.GifImageView
    android:id="@+id/GifImageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true" />

<mudasir.com.gifsimages.GIF.GifImageView
    android:id="@+id/GifImageView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/btnNextScreen"
    android:orientation="vertical">

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/cbk1"

        android:text="CickABle CheckBox" />

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"


        android:text="CickABle CheckBox" />

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"


        android:text="CickABle CheckBox" />
</LinearLayout>


<Button
    android:id="@+id/btnNextScreen"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_margin="10dp"
    android:text="NEXT SCREEN" />

</ScrollView>
</RelativeLayout>

Solution

  • scrollView must have one child ,so if you have one more child it will crash