Sam*_*net 6 android android-recyclerview
我正在尝试像Play Store应用首页一样使用CardView制作嵌套的recyclerview,到目前为止,它的工作原理还不如Play Store流畅。
当回收站视图滚动位置为0并且开始向右拖动时,边缘效果将如预期的那样出现,但是不久我继续向上拖动时,好像我的水平回收站视图失去了焦点,父级垂直视图接管了。从Play商店应用中,从边缘水平拖动后继续向上拖动时,您不会失去焦点。我坚持认为只有在回收者视图边缘时才会发生这种情况。
除此之外(这可能是相关的),从Play Store应用启动水平滚动看起来更容易,这意味着如果您从PlayStore应用启动了与水平方向成30°角的拖动,则会启动水平滚动,但是从我的应用中启动似乎我需要最大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>
Run Code Online (Sandbox Code Playgroud)
--
mList.setLayoutManager( new LinearLayoutManager( getContext( ),
LinearLayoutManager.VERTICAL,
false ) );
mList.setAdapter( new HomeAdapter( ) );
Run Code Online (Sandbox Code Playgroud)
这是嵌套的水平之一:
<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"/>
Run Code Online (Sandbox Code Playgroud)
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 );
}
Run Code Online (Sandbox Code Playgroud)
刚刚找到解决方案,从嵌套水平回收器视图添加:
childHorizontalList.addOnScrollListener( new RecyclerView.OnScrollListener( )
{
@Override
public void onScrollStateChanged( RecyclerView recyclerView, int newState )
{
super.onScrollStateChanged( recyclerView, newState );
parentVerticalList.setLayoutFrozen( newState != RecyclerView.SCROLL_STATE_IDLE );
}
} );
Run Code Online (Sandbox Code Playgroud)