How to make RelativeLayout scrollable with its fragment? - Kotlin

Viewed 92

i am trying to make this XML scroll-able:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:fancy="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/square_background"
tools:context=".ejournal.tabs.MyPlannerFragment">



<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/dimen_32"
    android:layout_marginHorizontal="@dimen/dimen_32"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="15dp"
        android:layout_gravity="center"
        android:src="@drawable/ic_myplanner"
      />

    <LinearLayout
        android:id="@+id/myplanner_folder"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
       android:layout_marginRight="15dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:fontFamily="@font/texgyreadventorregular"
            android:text="My Planner Folder"
            android:textColor="#C18FBC"
            android:textSize="13sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:fontFamily="@font/texgyreadventorregular"
            android:text="Click here to see all the events you have saved."
            android:textColor="#9D9D9D"
            android:textSize="13sp" />






    </LinearLayout>



</LinearLayout>

<LinearLayout
    android:layout_centerHorizontal="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/linearLayout"
    android:orientation="vertical">
    <CalendarView
        android:id="@+id/calender"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/linearLayout"
        android:layout_centerInParent="true"
        android:layout_marginTop="20dp">
    </CalendarView>
    <LinearLayout
        android:gravity="end"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <mehdi.sakout.fancybuttons.FancyButton
            android:id="@+id/btn_add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingBottom="15dp"
            android:paddingLeft="18dp"
            android:paddingRight="15dp"
            android:paddingTop="15dp"
            fancy:fb_borderColor="#FFFFFF"
            fancy:fb_borderWidth="1dp"
            fancy:fb_defaultColor="@color/purple_600"
            fancy:fb_focusColor="@color/purple_400"
            fancy:fb_fontIconResource="&#xf067;"
            fancy:fb_iconPosition="right"
            fancy:fb_text=""
            fancy:fb_radius="200dp"
            fancy:fb_textColor="#FFFFFF" />
    </LinearLayout>
    <LinearLayout
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:textAlignment="center"
            android:text="Pick a date to add your Daily Task/ Event"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal" />
    </LinearLayout>

</LinearLayout>

i tried to change "RelativeLayout" to "ScrollView" but i get an error in the fragment here:

inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?
): View? {
    // Inflate the layout for this fragment
    val root = inflater.inflate(R.layout.fragment_my_planner, container, false)

i changed "container" to "scrollview" but its the same error.

i also tried to add this to xml:

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"/>

but it didn't work as well.

what am i doing wrong here?

do i need to do changes for XML file only? or both fragment and xml?

1 Answers

Replace your Relative layout with ScrollView or just make parent of Relative layout hope this help you to solve your problem

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#fcf5eb"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:fitsSystemWindows="true"
   >

<Linear Layout>
.....





.....
</Linear Layout>

</Scrollview>


Related