【问题标题】:How to remain spanindex for StaggeredGridLayoutManager如何为 StaggeredGridLayoutManager 保留 spanindex
【发布时间】:2015-09-02 10:11:41
【问题描述】:

我将 RecyclerView 与 StaggeredGridLayoutManager 一起用于 2 个 SpanCount。每个项目都有以下布局。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/feed_item_margin_bottom"
android:layout_marginTop="@dimen/feed_item_margin_top"
android:background="#ffffff"
android:orientation="vertical" >

    <ImageView
        android:id="@+id/feed_photo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:src="@drawable/camera" />

    <TextView
        android:id="@+id/feed_caption"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="@dimen/feed_item_text_margin_left"
        android:layout_marginTop="@dimen/feed_item_text_margin_top"
        android:text="TextView"
        android:textColor="@color/color_primary_dark"
        android:visibility="gone" />

</LinearLayout>

默认情况下,TextView (id/feed_caption) 是不显示的,它会在项目被点击时显示。目前,显示会导致附近的项目更改spanindex,从而导致recyclerview的布局发生非常复杂的变化。 (我正在尝试添加动画)。

我想要实现的是所有项目都保留在自己的 spanindex 中。我搜索并没有找到一种方法。你能就任何事情提出建议吗?谢谢。

[edit]尝试添加动画来解释问题。(如果可能,请帮助让它直接显示在stackoverflow上)issue animation

【问题讨论】:

    标签: android android-recyclerview staggeredgridlayout


    【解决方案1】:

    我尝试了一种似乎可行的方法。如果您熟悉它,请您评论一下吗?有什么风险吗?

    我重写了 onItemUpdated 函数而不调用 base 的实现,这只会使 spanindex 设置无效。见以下代码

     @Override
    public void onItemsUpdated(RecyclerView recyclerView, int positionStart, int itemCount) {
        // super.onItemsUpdated(recyclerView, positionStart, itemCount);
    }
    

    【讨论】:

      猜你喜欢
      • 2015-08-05
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-28
      • 2017-11-18
      相关资源
      最近更新 更多