Как сделать RelativeLayout прокручиваемым с его фрагментом? — Котлин

#java #xml #kotlin #scroll #fragment

Вопрос:

я пытаюсь сделать этот 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"
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="amp;#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>
 

я попытался изменить «RelativeLayout» на «ScrollView», но здесь я получаю ошибку во фрагменте:

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

я изменил «контейнер» на «scrollview», но это та же ошибка.

я также попытался добавить это в xml:

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

но это тоже не сработало.

что я здесь делаю не так?

нужно ли вносить изменения только в XML-файл? или и фрагмент, и xml?

Ответ №1:

Замените относительный макет на ScrollView или просто сделайте родительский макет относительным, надеюсь, это поможет вам решить вашу проблему

 <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>


 

Комментарии:

1. всякий раз, когда я заменяю относительный макет на SrcollView, я получаю ошибку в этой строке » val root = inflater.inflate(R. макет. fragment_my_planner, контейнер, ложь)» во фрагменте