gpt4 book ai didi

java - ScrollView 不会在 ViewPager 中滚动

转载 作者:行者123 更新时间:2023-12-02 09:45:44 28 4
gpt4 key购买 nike

在我的应用程序中,我在工具栏下使用 TabLayout,并使用 ViewPager 填充其余空间。我需要选项卡下的 fragment 之一才能滚动。尝试使用 ScrollView、NestedScrollView 和 android:fillViewport="true"但没有成功。

我查看了有关同一问题的其他问题,尝试了答案中建议的任何内容,但它们都没有解决我的问题。

包含 ViewPager 代码的 Activity :

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout 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:orientation="vertical"
tools:context=".UserProfile">

<include
android:id="@+id/userToolbar"
layout="@layout/user_info_toolbar_layout" />

<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/userToolbar"
android:background="@android:color/holo_blue_light"
app:tabSelectedTextColor="@android:color/white"
app:tabTextColor="@android:color/black">

<com.google.android.material.tabs.TabItem
android:id="@+id/dashboardTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/dashboard_tab_text_en" />

<com.google.android.material.tabs.TabItem
android:id="@+id/statisticsTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/statistics_tab_text_en" />

</com.google.android.material.tabs.TabLayout>

<androidx.viewpager.widget.ViewPager
android:id="@+id/userInfoViewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/tabLayout" />


</androidx.constraintlayout.widget.ConstraintLayout>

fragment 的代码:

<?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:id="@+id/user_dashboard_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
tools:context=".Dashboard">

<androidx.constraintlayout.widget.ConstraintLayout
android:padding="40dp"
android:id="@+id/userInfoContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.github.abdularis.civ.CircleImageView
android:id="@+id/userImage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="@drawable/male_user_sample1"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/username_sample"
android:textColor="@color/colorPrimaryDark"
android:textSize="30sp"
app:layout_constraintTop_toBottomOf="@id/userImage" />

<com.ramijemli.percentagechartview.PercentageChartView
android:id="@+id/userLevelProgress"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="20dp"
android:outlineAmbientShadowColor="@color/colorPrimary"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/username"
app:pcv_animDuration="1000"
app:pcv_animInterpolator="anticipate_overshoot"
app:pcv_drawBackground="false"
app:pcv_drawBackgroundBar="false"
app:pcv_mode="ring"
app:pcv_orientation="counter_clockwise"
app:pcv_progress="100"
app:pcv_startAngle="270"
app:pcv_textColor="@color/colorPrimary"
app:pcv_textShadowRadius="100"
app:pcv_textSize="50sp" />

<TextView
android:id="@+id/userLevel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/level_sample"
android:textColor="@color/colorPrimary"
android:textSize="40sp"
app:layout_constraintTop_toBottomOf="@id/userLevelProgress" />


</androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>

我在代码中找不到导致 ViewPager 下的 fragment 无法滚动的问题。

最佳答案

回复这个

在您的ViewPager

 <androidx.viewpager.widget.ViewPager
android:id="@+id/userInfoViewPager"
android:layout_width="match_parent"
android:layout_height="0dp" // <- ****
app:layout_constraintBottom_toBottomOf="parent" // <- ****
app:layout_constraintTop_toBottomOf="@id/tablayout"
/>

然后,在 fragment xml中

<ScrollView
....
android:layout_width="match_parent"
android:layout_height="match_parent" // <- ****
>

<androidx.constraintlayout.widget.ConstraintLayout
android:padding="40dp"
android:id="@+id/userInfoContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" // <- ****
>

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

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