我在NestedScrollView中有一个ViewPager片段。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:background="@color/colorPrimary">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<androidx.core.widget.NestedScrollView
android:id="@+id/containerMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar"
android:fillViewport="true"
android:overScrollMode="never">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textHeader"
style="@style/BaseFontExtraBold"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="25dp"
android:text="My Meals"
android:textSize="@dimen/text_size_heading_large"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/containerCharts"
android:layout_width="0dp"
android:layout_height="150dp"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:baselineAligned="false"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textHeader">
<RelativeLayout
android:id="@+id/containerPlan"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp">
<com.github.lzyzsd.circleprogress.ArcProgress
android:id="@+id/mProgressPlan"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_centerInParent="true"
app:arc_finished_color="@color/colorWhite"
app:arc_text_color="@android:color/transparent"
app:arc_unfinished_color="@color/colorChartOuter" />
<TextView
android:id="@+id/textPlan"
style="@style/BaseFontExtraBold"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:gravity="center"
android:textSize="@dimen/text_size_heading_large" />
<TextView
android:id="@+id/textTitleMealPaln"
style="@style/BaseFontRegular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/mProgressPlan"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-5dp"
android:gravity="center"
android:text="@string/meal_plan"
android:textSize="@dimen/text_size_normal" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/containerConsumed"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp">
<com.github.lzyzsd.circleprogress.ArcProgress
android:id="@+id/mProgressConsumed"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_centerInParent="true"
app:arc_finished_color="@color/colorHorizontalNumberPicker"
app:arc_text_color="@android:color/transparent"
app:arc_unfinished_color="@color/colorChartOuter" />
<TextView
android:id="@+id/textConsumed"
style="@style/BaseFontExtraBold"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:gravity="center"
android:textSize="@dimen/text_size_heading_large" />
<TextView
android:id="@+id/textTitleConsumed"
style="@style/BaseFontRegular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/mProgressConsumed"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-5dp"
android:gravity="center"
android:text="@string/consumed"
android:textSize="@dimen/text_size_normal" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/containerRemaining"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp">
<com.github.lzyzsd.circleprogress.ArcProgress
android:id="@+id/mProgressRemaining"
android:layout_width="110dp"
android:layout_height="110dp"
android:layout_centerInParent="true"
app:arc_finished_color="@color/colorHorizontalNumberPicker"
app:arc_text_color="@android:color/transparent"
app:arc_unfinished_color="@color/colorChartOuter" />
<TextView
android:id="@+id/textRemaining"
style="@style/BaseFontExtraBold"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:gravity="center"
android:textSize="@dimen/text_size_heading_large" />
<TextView
android:id="@+id/textTitleRemaining"
style="@style/BaseFontRegular"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/mProgressRemaining"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-5dp"
android:gravity="center"
android:text="@string/remaining"
android:textSize="@dimen/text_size_normal" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="@+id/containerInfo"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/rounded_top_background"
android:orientation="vertical"
android:paddingStart="@dimen/spacing_l"
android:paddingTop="@dimen/spacing_l"
android:paddingEnd="@dimen/spacing_l"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/containerCharts"
app:layout_constraintBottom_toBottomOf="parent">
<RelativeLayout
android:id="@+id/containerHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/containerLeftArrow"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentStart="true"
android:background="@drawable/ic_previous_page" />
<TextView
android:id="@+id/textPageTitle"
style="@style/BaseFontExtraBold"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:text="Saturday, 23rd Nov"
android:textSize="@dimen/text_size_heading" />
<RelativeLayout
android:id="@+id/containerRightArrow"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:background="@drawable/ic_next_page" />
</RelativeLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPagerMeals"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/containerHeader"
android:layout_alignParentBottom="true"
android:layout_marginTop="20dp"
android:overScrollMode="never"
android:paddingBottom="15dp" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
使用片段实现的ViewPages
private inner class MealsListPagerAdapter(fm: FragmentManager?) : FragmentStatePagerAdapter(fm!!, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
override fun getCount(): Int = NUM_PAGES
override fun getItem(position: Int): Fragment = MealsListFragment()
}
在此ViewPager片段中,有几个回收站视图。我想在视图页面内滚动父片段。目前,它无法正常工作,并尝试将android:nestedScrollingEnabled =“ true”与ViewPager一起使用,但未成功。