【问题标题】:GridLayoutManager gravity rightGridLayoutManager 重力向右
【发布时间】:2015-08-12 11:47:39
【问题描述】:

我正在使用 RecyclerView 和 GridLayoutManager 在 Grid View 上显示项目,但我想将此项目右对齐意味着如果一行上有一个空单元格,这个空单元格应该在左边。

谢谢

【问题讨论】:

标签: android gridview right-to-left


【解决方案1】:

尝试使用此自定义GridLayoutManager 从右到左填充项目。

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.util.AttributeSet;

public class RtlGridLayoutManager extends GridLayoutManager {
    public RtlGridLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public RtlGridLayoutManager(Context context, int spanCount) {
        super(context, spanCount);
    }

    public RtlGridLayoutManager(Context context, int spanCount, int orientation, boolean reverseLayout) {
        super(context, spanCount, orientation, reverseLayout);
    }

    @Override
    protected boolean isLayoutRTL() {
        return true;
    }
}

【讨论】:

    【解决方案2】:

    尝试使用android:gravity="end"

    【讨论】:

    • 请编辑答案,因为它看起来更像是一条评论,因此很适合删除。
    • 但是我在审查低质量帖子时对Recommend deletion 有足够的声誉,顺便说一句,我没有为您的回答,轻轻地告知答案在队列中:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多