java - 如何使用它的片段使RelativeLayout 可滚动? - Kotlin

标签 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="&#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?

最佳答案

替换您的相对布局 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>


关于java - 如何使用它的片段使RelativeLayout 可滚动? - Kotlin ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67932369/

相关文章:

java - 为什么我们不重写 Spring CRUD Repository 中的方法

javascript - 如何编写查找父子的递归方法

Java:转换和继承

xml - XSD 唯一元素 XPath 限制

xml - 构造 XQuery 元素属性

api - Retrofit2 使用 GET 返回空响应体

JavaMail 正在丢失一些 POP3 邮件 header 并将 multipart/mixed 视为 text/plain

mysql - 存储和索引 1M+ XML 文档的最佳实践?

Android Kotlin - 使用 Bitmap 和 Glide 实现自定义 map 标记

kotlin - 在 http4k 中实现全局错误处理程序的惯用方式