Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ScrollView没有';不要在浏览页面中滚动_Java_Android_Xml_Android Viewpager_Scrollview - Fatal编程技术网

Java ScrollView没有';不要在浏览页面中滚动

Java ScrollView没有';不要在浏览页面中滚动,java,android,xml,android-viewpager,scrollview,Java,Android,Xml,Android Viewpager,Scrollview,在我的应用程序中,我在工具栏下使用了一个TabLayout,剩下的空间则是一个ViewPager。我需要选项卡下的一个片段才能滚动。尝试使用ScrollView、NestedScrollView和android:fillViewport=“true”但未成功 我看了关于同一问题的其他问题,尝试了答案中提出的任何建议,但都没有解决我的问题 包含ViewPager代码的活动: <?xml version="1.0" encoding="utf-8"?> <androidx.con

在我的应用程序中,我在工具栏下使用了一个TabLayout,剩下的空间则是一个ViewPager。我需要选项卡下的一个片段才能滚动。尝试使用ScrollView、NestedScrollView和android:fillViewport=“true”但未成功

我看了关于同一问题的其他问题,尝试了答案中提出的任何建议,但都没有解决我的问题

包含ViewPager代码的活动:

<?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>

片段的代码:

<?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下的片段不可滚动的问题。

似乎在
ConstraintLayout
内部
ScrollView
中存在一些错误,请不要忘记,如果您将某个视图的底部约束为constraint layout的底部<代码>滚动视图无法滚动。将
NestedScrollView
与viewport true配合使用对我来说很好

<android.support.v4.widget.NestedScrollView>
        ......
        ......
</android.support.v4.widget.NestedScrollView>

......
......

在您的
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"
 />

您是否检查过:您的viewpager滚动监听器与您的ScrollView冲突,probably@W0rmH0le我确实检查了这个,解决方案对我不起作用。是的!!!!成功了!!非常感谢你,我也被困在这个问题上了long@IronMan很乐意帮忙!
<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" // <- ****
    >