android - 滚动视图没有完全滚动
问题描述
在我的主要活动中,有导航抽屉和 fab 按钮以及 content.xml 内部,这是在我的主要活动中加载内容的主要 xml。换句话说,我有 android studio 提供的导航抽屉活动。
该 content.xml 中的代码是:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/b1"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#f0eb79"
android:foreground="?attr/selectableItemBackground"
android:drawableTop="@drawable/computer"
android:paddingTop="25dp"
android:text="Chemistry"
android:textAllCaps="false"
android:textColor="#2f2e2e"
android:textSize="18sp" />
<Button
android:id="@+id/b2"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#524d47"
android:foreground="?attr/selectableItemBackground"
android:drawableTop="@drawable/computer"
android:paddingTop="25dp"
android:text="Sports"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/b3"
android:layout_width="0dp"
android:foreground="?attr/selectableItemBackground"
android:layout_height="200dp"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="#e7595d"
android:drawableLeft="@drawable/computer"
android:paddingLeft="45dp"
android:text="Inventions"
android:textAllCaps="false"
android:textColor="#fff"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
如下图所示,它并没有完全滚动。我还在另一个没有 fab 和 nagivation 抽屉的空活动中测试了相同的 xml 代码,并且它完美地显示了滚动行为。
同样,这是我的 activitymain.xml 的代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
解决方案
在滚动视图中添加这些属性后,它对我有用:
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.nepali_test.MainActivity"
tools:showIn="@layout/app_bar_main"
推荐阅读
- reactjs - 如何使用 NextJS 和 next-i18next 翻译路线?
- oracle - 什么是 Sqlite 中的等效 oracle 查询 trunc(date)?
- object - 将 1 个对象的值映射到其他对象的键
- nginx - NGINX 返回 301 而不是 404
- docker - docker-compose之后的网络与定义的名称不同?
- javascript - 所有对象的 Javascript 警报
- pandas - 名称“_Unspecified”未定义
- javascript - javascript:将对象添加到数组会更改对象属性
- mql5 - 我该如何解决这个问题:“'Price.mqh' (57,12) 中的数组超出范围”?
- python - 如何按字母顺序返回文本文件中的所有单词(每个单词一次)?