gpt4 book ai didi

android - ScrollView 不在 fragment 中滚动

转载 作者:行者123 更新时间:2023-11-29 14:46:28 24 4
gpt4 key购买 nike

我用谷歌搜索了我的问题并在 stackoverflow 中阅读了类似的问题,但我没有解决任何问题。

我有一个带有 coordinatorLayout (main.xml) 的布局和一个带有 relativeLayout (fragment.xml) 的 fragment

main.xml

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:paddingRight="16dp"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:text="FRAGMENT TITLE"
android:textSize="20sp"
android:textColor="@color/colorWhite"
android:id="@+id/main_toolbar_title"
android:gravity="center_vertical" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:background="@color/colorWhite"
android:layout_width="match_parent"
android:layout_height="60dp" />
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

fragment.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:background="#f3f3f3">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:contentPadding="1dp"
card_view:cardCornerRadius="2dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<Button
android:layout_width="match_parent"
android:layout_height="66dp"
android:textAllCaps="false"
android:text="Button Title"
android:textSize="18sp"
android:textColor="#404040"/>
<Button
android:layout_width="match_parent"
android:layout_height="66dp"
android:textAllCaps="false"
android:text="Button Title"
android:textSize="18sp"
android:textColor="#404040"/>
<Button
android:layout_width="match_parent"
android:layout_height="66dp"
android:textAllCaps="false"
android:text="Button Title"
android:textSize="18sp"
android:textColor="#404040"/>
<Button
android:layout_width="match_parent"
android:layout_height="66dp"
android:textAllCaps="false"
android:text="Button Title"
android:textSize="18sp"
android:textColor="#404040"/>
<Button
android:layout_width="match_parent"
android:layout_height="66dp"
android:textAllCaps="false"
android:text="Button Title"
android:textSize="18sp"
android:textColor="#404040"/>
<Button
android:layout_width="match_parent"
android:layout_height="66dp"
android:textAllCaps="false"
android:text="Button Title"
android:textSize="18sp"
android:textColor="#404040"/>
<Button
android:layout_width="match_parent"
android:layout_height="66dp"
android:textAllCaps="false"
android:text="Button Title"
android:textSize="18sp"
android:textColor="#404040"/>
<Button
android:layout_width="match_parent"
android:layout_height="66dp"
android:textAllCaps="false"
android:text="Button Title"
android:textSize="18sp"
android:textColor="#404040"/>

</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
</RelativeLayout>

如您所见,我在 scrollView 中有更多按钮但没有滚动。 view pager中的ui元素,我一开始以为是因为view pager,但我测试了test_fragment.xml,它完美运行。

当我在 View 寻呼机之外按住不放时,scrollView 会滚动(例如,我的第一个选项卡) 并向上/向下移动手指

test_fragment.xml

<android.support.design.widget.CoordinatorLayout
android:id="@+id/quickreturn_coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

问题是什么?

提前致谢。

最佳答案

当您使用 AppBarLayout 时,它不适用于简单的 ScrollView。您应该改用 NestedScrollview。并且您已将 ScrollView 置于 RelativeLayout 中,这不是必需的。再次尝试使用 NestedScrollView 删除 RelativeLayout

我想这会有所帮助。

关于android - ScrollView 不在 fragment 中滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35822202/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com