相关疑难解决方法(0)

Android使用gridlayoutmanager在recyclerview中的最后一个元素下添加间距

我试图在增加最后一个元件行下面的间距RecyclerViewGridLayoutManager.ItemDecoration为了这个目的,我使用自定义底部填充,当它的最后一个元素如下:

public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
private int space;
private int bottomSpace = 0;

public SpaceItemDecoration(int space, int bottomSpace) {
    this.space = space;
    this.bottomSpace = bottomSpace;
}

public SpaceItemDecoration(int space) {
    this.space = space;
    this.bottomSpace = 0;
}

@Override
public void getItemOffsets(Rect outRect, View view,
                           RecyclerView parent, RecyclerView.State state) {

    int childCount = parent.getChildCount();
    final int itemPosition = parent.getChildAdapterPosition(view);
    final int itemCount = state.getItemCount();

    outRect.left = space;
    outRect.right = space;
    outRect.bottom = space; …
Run Code Online (Sandbox Code Playgroud)

android gridlayoutmanager android-recyclerview

71
推荐指数
4
解决办法
3万
查看次数

如何在RecyclerView中使用fastScrollEnabled?

我是RecyclerView的新手,我想在RecyclerView中实现快速滚动功能,如谷歌联系人应用程序和在互联网上搜索,我发现现在Android fastScrollEnabled为RecyclerView 提供正式的新布尔标志.所以我的问题是有人可以提供它的示例实现.

以下是来自Google https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-0的官方文档

android android-recyclerview

16
推荐指数
2
解决办法
1万
查看次数

RecyclerView与不同高度的项目:滚动条

我有一个RecyclerView带滚动条的不同高度的项目.由于项目的高度不同,滚动条会更改其垂直大小,具体取决于当前显示的项目(请参见屏幕截图).我创建了一个示例项目,在这里显示问题.

  1. 有没有人有同样的问题并修复它?
  2. 如何覆盖滚动条高度和位置的计算以得出自己的实现?

编辑:滚动条的位置和高度可以通过覆盖进行控制RecyclerViews computeVerticalScrollOffset,computeVerticalScrollRangecomputeVerticalScrollExtent.我不知道如何实现这些以使滚动条与动态项目高度正常工作.

我想,问题是RecyclerView根据当前可见的项目估算所有项目的总高度,并相应地设置滚动条的位置和高度.解决这个问题的一种方法可能是更好地估计所有物品的总高度.

大滚动条 小滚动条

android scrollbar android-recyclerview

12
推荐指数
1
解决办法
3964
查看次数

在android中启用RecyclerView快速滚动设置固定高度滚动拇指

我使用以下属性实现了 RecyclerView 快速滚动:

<android.support.v7.widget.RecyclerView
...
 app:fastScrollEnabled="true"
 app:fastScrollHorizontalThumbDrawable="@drawable/fast_scroll_thumb"
 app:fastScrollHorizontalTrackDrawable="@drawable/fast_scroll_track"
 app:fastScrollVerticalThumbDrawable="@drawable/fast_scroll_thumb"
 app:fastScrollVerticalTrackDrawable="@drawable/fast_scroll_track"/>
Run Code Online (Sandbox Code Playgroud)

fast_scroll_thumb.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <solid android:color="@color/lightBlue" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/lightBlue" />
        </shape>
    </item>
</selector>
Run Code Online (Sandbox Code Playgroud)

fast_scroll_track.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/gray" />
</shape>
Run Code Online (Sandbox Code Playgroud)

但是,快速滚动拇指大小取决于数据数量。随着 RecyclerView 数据的增加,拇指大小减小。有没有办法将拇指大小固定在固定高度?

android fastscroll android-recyclerview

7
推荐指数
0
解决办法
1120
查看次数