微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我尝试在片段中使用 ScrollView,但它不起作用

如何解决我尝试在片段中使用 ScrollView,但它不起作用

我有一个关于我的 Android 应用的问题。我有一个包含不同选项的菜单。对于主页按钮,我使用了一个片段,我想在其中滚动。第一次,我在fragment xml中添加了ScrollView,但是根本不起作用。然后,我在带有菜单的主活动中尝试了 ScrollView,但没有奏效。

这里是主要的活动xml:

Error: incompatible types when assigning to type Participant from type struct Participant

这里是片段xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:isScrollContainer="false">

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".MainActivity">

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/bottomAppBar" />

    <com.google.android.material.bottomappbar.BottomAppBar
        android:id="@+id/bottomAppBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:backgroundTint="@color/green_700"
        app:fabAlignmentMode="center"
        app:fabCradleMargin="10dp"
        app:fabCradleRoundedCornerRadius="30dp"
        app:fabCradLeverticalOffset="10dp"
        app:contentInsetStart="0dp">

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNavigationView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:itemIconTint="@color/light_grey"
            app:itemTextColor="@color/light_grey"
            app:itemTextAppearanceActive="@font/josefin_sans_semibold"
            android:background="@drawable/background_transparent"
            app:menu="@menu/bottom_navigation_menu" />

    </com.google.android.material.bottomappbar.BottomAppBar>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="onPressFab"
        android:src="@drawable/ic_add"
        app:layout_anchor="@id/bottomAppBar" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</ScrollView>

如果您有任何建议,我将不胜感激。谢谢!

解决方法

我不确定我是否正确理解了您的用例,但如果您希望片段可滚动,则在片段布局中使用 scrollview 并确保 android:isScrollContainer 设置为 true。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。