我正在尝试使用嵌套滚动条来滚动固定的viewpager。问题是我能够在固定的viewpager上滚动内容,但我无法滑动viewpager以更改产品图片。我尝试了CollapsingToolbar,但它没有起作用。因此,我开发了另一个布局,它可以做到我想要的事情,但问题是它与viewpager不兼容。这是我的当前布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
tools:context="org.kiranahouse.activity.SingleProductActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp"
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:background="@color/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:collapseIcon="@drawable/back_colored"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/product_image_pager"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="60dp">
</android.support.v4.view.ViewPager>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_below="@+id/product_image_pager">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="24dp"
android:id="@+id/pager_tab_layout"
app:tabBackground="@drawable/tab_selector"
app:tabIndicatorHeight="0dp"
app:tabGravity="center">
</android.support.design.widget.TabLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:elevation="12dp"
android:layout_marginBottom="56dp">
<LinearLayout
android:paddingTop="250dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#fafafa">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="4dp"
app:cardCornerRadius="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<org.kiranahouse.component.CustomTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product Name"
android:textColor="@color/normalButtonGradientEnd"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/product_title"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/product_title"
android:layout_marginTop="8dp">
<org.kiranahouse.component.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:layout_alignParentLeft="true"
android:text="Rs. 1024"
android:id="@+id/actual_price"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/primaryTextColor"
android:layout_centerVertical="true"/>
<org.kiranahouse.component.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/actual_price"
android:layout_marginLeft="16dp"
android:text="Rs. 2999"
android:id="@+id/old_price"
android:layout_centerVertical="true"/>
<org.kiranahouse.component.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="28 % Off"
android:layout_alignParentRight="true"
android:background="@drawable/discount_single_product"
android:paddingTop="4dp"
android:paddingBottom="2dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:id="@+id/discount_percentage"
android:layout_centerVertical="true"/>
</RelativeLayout>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/customDividerColor"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="1"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="-1"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_reply"
android:tint="@color/dividerColor"
android:layout_marginRight="4dp"/>
<org.kiranahouse.component.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Share"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
<View
android:layout_width="1sp"
android:layout_height="match_parent"
android:background="@color/customDividerColor"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_weight="1"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleX="-1"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_favorite"
android:tint="@color/dividerColor"
android:layout_marginRight="4dp"/>
<org.kiranahouse.component.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Wishlist"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:elevation="4dp"
app:cardCornerRadius="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="vertical">
<org.kiranahouse.component.CustomTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Unit"
android:textColor="@color/secondaryTextColor"/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:elevation="4dp"
app:cardCornerRadius="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="600dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<org.kiranahouse.component.CustomButton
android:layout_width="match_parent"
android:layout_height="48dp"
app:radius="0"
app:startColor="@color/normalButtonGradientStart"
app:endColor="@color/normalButtonGradientEnd"
android:text="Add to Cart"
android:gravity="center"
android:elevation="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
这是我拍摄的屏幕截图:
![图片描述](https://istack.dev59.com/FRlfo.webp)
![图片描述](https://istack.dev59.com/0Cwp4.webp)
![图片描述](https://istack.dev59.com/67isB.webp)