【问题标题】:why wont my recycler view scroll?为什么我的回收站视图不滚动?
【发布时间】:2016-05-01 17:58:54
【问题描述】:

由于很多原因,我一直在网上浏览这似乎发生了很多事情,但我无法解决我的两个回收器视图进入视图寻呼机但不会滚动,我尝试了视图寻呼机上的嵌套滚动视图和在持有回收器视图的片段上,尝试仅在线性布局上使用滚动行为标签,但不高兴我尝试将布局管理器更改为水平,虽然它不滚动,但它确实在最后给了我滚动视图的动画它的布局,我使用的是网格布局,我也听说它可以来自使用应用栏布局,有人可以提供一些建议

<?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"
android:fitsSystemWindows="true"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/wherethecardsgo">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/border"
            android:layout_margin="10dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
             />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_playlist_play_white_24dp"
        android:layout_alignBottom="@id/viewpager2"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    </RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

<android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="scrollable"
        app:tabGravity="fill"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />


<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:background="@color/windowBackground"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_below="@+id/tabs" />

</RelativeLayout>
    </LinearLayout>
</RelativeLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" />


<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/plus" />

</android.support.design.widget.CoordinatorLayout>

这是回收者的观点之一

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TwoFragment">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/card_grid"
        android:scrollbars="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</RelativeLayout>

【问题讨论】:

  • recyclerview 的某些部分的最后一个不滚动。这是你的问题吗?
  • 是的 @Masum 回收站视图不会滚动,所以屏幕的最后一部分丢失了,在半可见的行下还有 1 行卡片

标签: android android-fragments scroll android-viewpager android-recyclerview


【解决方案1】:

在你的 recyclerView 中添加这两个属性。

android:clipToPadding="false"
android:paddingBottom="60dp"

paddingBottom 值您可以根据需要更改

【讨论】:

  • 喜欢你的想法,但这没有用,尝试从 60 到 160 再到 260 一直到 2660,但它就是不想滚动
【解决方案2】:

已解决

这是 appbar 窃取焦点的问题,所以我将 appbar 推到布局的底部,突然我的回收站视图开始滚动!我的 xml 现在看起来像这样

<?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"
android:fitsSystemWindows="true"
tools:context=".MainActivity">



<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/colorPrimary"
    android:id="@+id/wherethecardsgo">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/border"
            android:layout_marginLeft="10dp"
            android:layout_marginBottom="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="64dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
             />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_playlist_play_white_24dp"
        android:layout_alignBottom="@id/viewpager2"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    </RelativeLayout>


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

<android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
        app:tabMode="scrollable"
        app:tabGravity="fill"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />


<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:background="@color/windowBackground"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_below="@+id/tabs" />

</RelativeLayout>
    </LinearLayout>
</RelativeLayout>

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/plus" />

</android.support.design.widget.CoordinatorLayout>

【讨论】:

    【解决方案3】:

    或者使用它 简单地在你的活动或片段中试试这个

    recyclerView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                getView().getParent().requestDisallowInterceptTouchEvent(true); // Pour Le Scroll pour qu'il soit opérationnel
                return false;
            }
        });
    

    【讨论】:

      猜你喜欢
      • 2016-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      相关资源
      最近更新 更多