【问题标题】:Nested recyclerview view like play Play Store app嵌套 recyclerview 视图,如 Play Play 商店应用
【发布时间】:2017-03-08 11:37:43
【问题描述】:

我正在尝试使用 CardView 制作嵌套的 recyclerview,例如 Play Store 应用主页,到目前为止它可以工作,但不如 Play Store 流畅。

当回收器视图滚动位置为 0 并且我开始向右拖动时,边缘效果按预期显示,但很快我继续向上拖动它看起来我的水平回收器视图失去焦点并且父垂直视图接管。从 Play 商店应用程序中,在从边缘水平拖动后继续向上拖动时,您不会失去焦点。 我坚持认为只有当我在回收站视图边缘时才会发生这种情况。

除此之外(这可能是相关的),从 Play Store 应用启动水平滚动看起来更容易,我的意思是,如果您从水平方向拖动 30° 角并启动 PlayStore 应用水平滚动,但从我的应用似乎需要一个最大 10° 的角度来启动我的应用,否则垂直滚动会接管。

这是我的垂直回收器视图代码(在协调器布局内):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          style="@style/AppStyle.Fragment"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="?attr/colorPrimary"
        android:gravity="center"
        android:text="weather / places"
        android:textColor="@android:color/white"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>
</LinearLayout>

-

mList.setLayoutManager( new LinearLayoutManager( getContext( ),
                                                LinearLayoutManager.VERTICAL,
                                                     false ) );
mList.setAdapter( new HomeAdapter( ) );

这里是嵌套的水平一:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:padding="@dimen/screen_padding">

<TextView
    android:id="@+id/title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fontFamily="sans-serif-medium"
    android:paddingLeft="4dp"
    android:paddingRight="4dp"
    android:textSize="18sp"
    tools:text="hello world"/>

<Space
    android:layout_width="match_parent"
    android:layout_height="10dp"/>

<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_marginLeft="4dp"
    android:layout_marginRight="4dp"
    android:background="@color/divider"/>

<Space
    android:layout_width="match_parent"
    android:layout_height="20dp"/>

<android.support.v7.widget.RecyclerView
    android:id="@+id/list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:fadingEdgeLength="30dp"
    android:requiresFadingEdge="horizontal"/>

ListViewHolder( View itemView )
{
    super( itemView );

    list.setLayoutManager( new LinearLayoutManager( getContext( ),
                                                        LinearLayoutManager.HORIZONTAL,
                                                        false ) );
    list.setHasFixedSize( true );
    SnapHelper snapHelper = new LinearSnapHelper( );
    snapHelper.attachToRecyclerView( list );
    list.setAdapter( new ListAdapter( ) );
    list.setNestedScrollingEnabled( false );
}

【问题讨论】:

    标签: android android-recyclerview


    【解决方案1】:

    刚刚找到的解决方案,来自嵌套的水平回收器视图添加:

    childHorizontalList.addOnScrollListener( new RecyclerView.OnScrollListener( )
    {
        @Override
        public void onScrollStateChanged( RecyclerView recyclerView, int newState )
        {
            super.onScrollStateChanged( recyclerView, newState );
    
            parentVerticalList.setLayoutFrozen( newState != RecyclerView.SCROLL_STATE_IDLE );
        }
    } );
    

    【讨论】:

    • 哇好!非常感谢;)
    猜你喜欢
    • 2016-04-05
    • 2015-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多