[英]Android Scroll Problems - CoordinatorLayout + CollapsingToolBarLayout + View Pager + Recycler View
我在滾動我的recyclerview時遇到問題。 我試圖實現視差圖像效果,所以我找到了本教程並采用了它。 之后,我注意到viewpager中的回收者視圖不再滾動。
我研究了一些解決方案:我找到了 ,但是似乎沒有任何效果。
這是我的XML下面:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/rel_layout_size"
android:background="@android:color/white"
android:orientation="horizontal"
android:focusable="true"
>
<ImageView
android:id="@+id/search_icon"
android:layout_width="@dimen/icons_size"
android:layout_height="@dimen/icons_size"
android:src="@drawable/search"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="10dp"
/>
<ImageView
android:id="@+id/like_icon"
android:layout_width="@dimen/icons_size"
android:layout_height="@dimen/icons_size"
android:src="@drawable/like"
android:layout_toStartOf="@id/search_icon"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
</RelativeLayout>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@android:color/white"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:theme="@style/AppTheme.LightActionBar"
app:contentScrim="@android:color/white"
android:fitsSystemWindows="true"
>
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/htab_collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:fitsSystemWindows="true"
app:contentScrim="@android:color/white"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/home"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.75"
/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.1"
android:background="@android:color/white"
android:fitsSystemWindows="true"/>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_gravity="top"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@android:color/white"
app:tabIndicatorColor="@android:color/black"
app:tabSelectedTextColor="@android:color/black"
app:tabTextColor="@android:color/darker_gray"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<xyz.santeri.wvp.WrappingViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
片段XML示例如下所示:
<android.support.v4.widget.NestedScrollView
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:fillViewport="true"
android:layout_gravity="fill_vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewArtworks"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
稍后我找到了解決方案。 原來RelativeLayout對其進行了修復。 這可以幫助某人
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/search_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/rel_layout_size"
android:background="@android:color/white"
android:orientation="horizontal"
android:layout_alignParentTop="true"
android:focusable="true"
>
<ImageView
android:id="@+id/search_icon"
android:layout_width="@dimen/icons_size"
android:layout_height="@dimen/icons_size"
android:src="@drawable/search"
android:layout_alignParentEnd="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="15dp"
android:layout_marginLeft="10dp"
/>
<ImageView
android:id="@+id/like_icon"
android:layout_width="@dimen/icons_size"
android:layout_height="@dimen/icons_size"
android:src="@drawable/like"
android:layout_toStartOf="@id/search_icon"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
</RelativeLayout>
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_below="@+id/search_bar"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@android:color/white"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:theme="@style/AppTheme.LightActionBar"
app:contentScrim="@android:color/white"
android:fitsSystemWindows="true"
>
<!--android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"-->
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/htab_collapse_toolbar"
android:layout_width="match_parent"
android:layout_height="200dp"
android:fitsSystemWindows="true"
app:contentScrim="@android:color/white"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:titleEnabled="false">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/home"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.75"
/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.1"
android:background="@android:color/white"
android:fitsSystemWindows="true"/>
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_gravity="top"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<!--android:layout_height="?attr/actionBarSize"-->
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@android:color/white"
app:tabIndicatorColor="@android:color/black"
app:tabSelectedTextColor="@android:color/black"
app:tabTextColor="@android:color/darker_gray"
android:fillViewport="false" />
</android.support.design.widget.CollapsingToolbarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
</android.support.design.widget.AppBarLayout>
<!--<xyz.santeri.wvp.WrappingViewPager-->
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
/>
</android.support.design.widget.CoordinatorLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.