java - 如何使用其片段使 RelativeLayout 可滚动?- 科特林
问题描述
我正在尝试使此 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=""
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)
我将“容器”更改为“滚动视图”,但同样的错误。
我还尝试将其添加到 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>
推荐阅读
- c# - 在 Azure 设备预配服务中上传证书
- node.js - 如何获取时刻时区使用的时区版本?
- c# - Twitter API - 发布后删除具有唯一 ID 的推文
- arrays - 在数组中无法显示前 9 个字符
- php - 从 CI4 中的另一个模型访问模型函数的正确方法是什么?
- react-native - BottomTabNavigator 中的动态 initialRouteName - React Navigation v5
- git - 尽管具有执行权限,但接收后 gitook 不会触发?
- artificial-intelligence - 如何区分从左到右和从右到左的 alpha-beta 修剪?
- angular - 在 Angular 9 中使用查询参数导航到 url
- haskell - 为什么这个的第二个版本在指数时间内运行?