我正在使用RecyclerView(com.android.support:recyclerview-v7:21.0.2)GridLayoutManager并应用动态列数。滚动视图时,将引发异常。当RecyclerView即将显示以前未显示的项目(重新使用或重新绑定)时,似乎发生了错误。但是,如果我不使用这样的动态跨度/列数,或者只是注释行调用GridLayoutManager.setSpanCount,则不会发生。
我试图检查源代码,看来问题与临时数组有关mSet。
E/AndroidRuntime? FATAL EXCEPTION: main
java.lang.ArrayIndexOutOfBoundsException
at android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:361)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1269)
at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1097)
at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:957)
at android.support.v7.widget.RecyclerView.scrollByInternal(RecyclerView.java:985)
at android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:1686)
at android.view.View.dispatchTouchEvent(View.java:3885)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) …Run Code Online (Sandbox Code Playgroud) 我有一个带有GridLayoutManager的RecyclerView(支持lib v7)。我更新适配器,并使notifyItemMoved。如果项目的源位置在屏幕上并且目标位置也在屏幕上-则播放“移动动画”。如果项目位于屏幕外的位置(位置1000,或远离视口的任何其他位置)并移入视口,它将显示为“淡入动画”。
尽管supportsPredictiveItemAnimations()返回true,但看起来预测项目动画无法正常工作。难道我做错了什么?我应该重写一些方法来启用它吗?
我正在阅读RecyclerView的源代码,并且在dispatchdoc方法的javadoc中的编写方式如下:
- 永久视图已移动({@link ItemAnimator#animateMove(ViewHolder,int,int,int,int)})
- 已删除的视图已删除({@link ItemAnimator#animateRemove(ViewHolder)})
- 添加了添加的视图({@link ItemAnimator#animateAdd(ViewHolder)})
- 消失的视图移出屏幕
- 出现的视图在屏幕上移动
但是,ItemAnimator不能区分ADDED和APPEARING。是否可以修复预报动画或至少使APPEARING动画看起来像“从屏幕动画之外移动”,而将添加的动画保持原样?
我正在RecyclerView和GridLayout经理一起使用,以便像旅行一样预订座位.
我的问题是当我的列是随机的时候如何自动检测spancount?
我知道spanCount = recyclerViewWidth / singleItemWidth;,但问题是singleItemWidth不同的,因为座位宽度不同.
这是我想要的所需布局:
...但我现在得到这样的东西:
这是我用来安排座位布局的代码:
gridLayoutManager=new GridLayoutManager(this,totalRows, LinearLayoutManager.VERTICAL,
false);
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
int rows=Integer.parseInt(upperlist.get(position).get("row"));
return (rows);///(int) (mRecyclerView.getMeasuredWidth()/ 10);
}
});
mRecyclerView.setLayoutManager( gridLayoutManager);
MyAdapter myAdapter=new MyAdapter(this,gridArray);
Run Code Online (Sandbox Code Playgroud)
... upperlist保持这些值:
[{cols=8, seatNumber=29U, row=4, zindex=1},
{cols=6,seatNumber=23U, row=4, zindex=1},
{cols=4,seatNumber=21U,row=4, zindex=1},
{cols=2, seatNumber=11U, row=4, zindex=1},
{cols=0,seatNumber=9U,row=4, zindex=1},
{cols=8,seatNumber=25U, row=2, zindex=1},
{cols=6,seatNumber=17U, row=2, zindex=1},
{cols=4,seatNumber=13U, row=2, zindex=1},
{cols=2,seatNumber=5U, row=2, zindex=1},
{cols=10, seatNumber=D2U,row=2, zindex=1},
{cols=0, seatNumber=1U, row=2, …Run Code Online (Sandbox Code Playgroud) 我想有一个完整的网格格栅RecyclerView与GridLayoutManager出于某种原因,行之间,并在我的顶部和底部增加了一个水平的空间,但RecyclerView.我无法摆脱它.我搜索了解决方案并尝试ItemDecorator通过将维度明确设置为0,但这不起作用.没有其他工作.
该图像.
我的代码ItemDecorator非常标准,包括在内.
private class RecyclerViewItemDecorator extends RecyclerView.ItemDecoration {
private int spaceInPixels;
public RecyclerViewItemDecorator(int spaceInPixels) {
this.spaceInPixels = spaceInPixels;
}
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
outRect.left = spaceInPixels;
outRect.right = spaceInPixels;
outRect.bottom = spaceInPixels;
if (parent.getChildLayoutPosition(view) == 0) {
outRect.top = spaceInPixels;
} else {
outRect.top = 0;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这些是我使用的布局文件.
/layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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" …Run Code Online (Sandbox Code Playgroud) 我继承了一个带有大量旧代码的大型项目,现在我遇到了一些奇怪的问题。
我需要使此屏幕具有带有网格布局管理器的recyclerview(2列)。这就是我得到的。有没有办法将这些图标放在屏幕中间?我试过重力,但无济于事。可能所有旧代码中都存在问题,或者仅仅是recyclerView的问题?
这是项目的布局(糟糕,请不要问..)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_view_controller_item_background"
android:orientation="vertical">
<TextView
android:id="@+id/textViewSceneKK"
android:layout_width="match_parent"
android:layout_height="@dimen/room_button_height"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/row_filter_text_margin_left"
android:layout_marginRight="@dimen/row_filter_text_margin_left"
android:gravity="center"
android:shadowDx="-1"
android:shadowDy="-1"
android:shadowRadius="1"
android:textSize="@dimen/row_scene_kk_text_size" />
<TextView
android:id="@+id/textViewSceneName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/row_filter_text_margin_bottom"
android:layout_marginLeft="@dimen/row_filter_text_margin_left"
android:layout_marginRight="@dimen/row_filter_text_margin_left"
android:layout_marginTop="@dimen/row_filter_text_margin_top"
android:clickable="false"
android:gravity="center"
android:longClickable="false"
android:textColor="@color/main_text_color"
android:textSize="@dimen/row_browser_right_name_text_size" />
</LinearLayout>
<!--<View-->
<!--android:id="@+id/filterView"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:clickable="false"-->
<!--android:longClickable="false" />-->
<View
android:id="@+id/filterViewClick"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:selectableItemBackground"
android:focusable="false"
android:focusableInTouchMode="false" />
Run Code Online (Sandbox Code Playgroud)
而不是布局:
<customview.CustomRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none" />
Run Code Online (Sandbox Code Playgroud)
和代码:
customRecyclerView.setHasFixedSize(false);
customRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
customRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(),
R.drawable.line_separator_empty, DividerItemDecoration.VERTICAL_LIST));
customRecyclerView.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
CustomRecyclerView.java
public class CustomRecyclerView extends RecyclerView …Run Code Online (Sandbox Code Playgroud) 我使用RecyclerViewwith GridLayoutManager来显示网格图案中的一些项目.它运行良好并在网格内的2列中显示项目.
但是当项目的数量是奇数时,我希望最后一项必须是全宽(与宽度相同RecyclerView).
无论如何使用GridLayoutManager或我必须建立自定义设计?
请帮忙.
我正在使用带有2个单元格的GridLayoutManager,对于某些单元格,我希望span为1,所以我尝试使用setSpanSizeLookup但它不起作用.我尝试为所有位置返回跨度计数1,但仍然出现两个单元而不是一个.
以下是我的代码
gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return 1;
}
});
recyclerView.setLayoutManager(gridLayoutManager);
Run Code Online (Sandbox Code Playgroud)
有什么原因导致它不起作用?
android android-support-library gridlayoutmanager android-recyclerview
我RecyclerView使用GridLayoutManager具有动态列号的a呈现不同类型的项目。问题是,我有一个RecyclerView.ItemDecoration只适用于让我们说Type A项目。这RecyclerView.ItemDecoration会在左侧列中的那些项目的左侧/开始处添加边距,并在右侧列中的那些项目的右侧/结尾处添加边距。它基本上是为了使项目看起来更居中并因此拉伸(这用于平板电脑/横向模式)。该RecyclerView网格看起来是这样的:
| A | | A |
| A | | A |
| B |
| A | | A |
| A | | A |
| B |
| A | | A |
Run Code Online (Sandbox Code Playgroud)
该ItemDecoration如下所示:
class TabletGridSpaceItemDecoration(private val space: Int) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) = with(outRect) {
val isTypeAItemLayout = view.findViewById<ConstraintLayout>(R.id.type_a_item_container) != null …Run Code Online (Sandbox Code Playgroud) android gridlayoutmanager android-recyclerview recyclerview-layout item-decoration
集跨度的大小比1GridLayoutManager的时候LoadState是Loading在寻呼库。我已经尝试过这个解决方案,但它不起作用。
对于重复的问题:克隆这个官方回购和设置GridLayoutManager在SearchRepositoriesActivity
我的代码在这里
电影列表片段
....
private val adapter = MoviesAdapter()
....
private fun initAdapter() {
val decoration = DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL)
binding.rvMovies.addItemDecoration(decoration)
binding.rvMovies.layoutManager = GridLayoutManager(requireContext(), 2)
binding.rvMovies.isNestedScrollingEnabled = true
binding.rvMovies.adapter = adapter.withLoadStateFooter(
footer = MoviesLoadStateAdapter { adapter.retry() }
)
}
Run Code Online (Sandbox Code Playgroud)
电影适配器
class MoviesAdapter(
) : PagingDataAdapter<Movie, MoviesAdapter.ViewHolder>(MOVIE_COMPARATOR) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = ItemMovieListBinding.inflate(LayoutInflater.from(parent.context))
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: …Run Code Online (Sandbox Code Playgroud) android gridlayoutmanager android-recyclerview android-paging-library
android ×10