我有一个关于我的 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>
如果您有任何建议,我将不胜感激。谢谢!
答案 0 :(得分:0)
我不确定我是否正确理解了您的用例,但如果您希望片段可滚动,则在片段布局中使用 scrollview 并确保 android:isScrollContainer
设置为 true。