简体   繁体   English

Android,包装RecyclerView LayoutManager,RTL,自下而上

[英]Android, Wrapping RecyclerView LayoutManager, RTL, Bottom-To-Top

I have a RecyclerView which uses a LayoutManager to lay-out data like this...我有一个 RecyclerView 它使用 LayoutManager 来布置这样的数据......

[...][5][4][3][2][1]

But I want to make it do this...但我想让它做到这一点......

   [9][8][7][6]
[5][4][3][2][1]

How can I?我怎样才能?

I have attempted to use a GridLayoutManager, but I can't make it start at the bottom-right corner and proceed left then up.我尝试使用 GridLayoutManager,但我无法让它从右下角开始,然后从左到上。

Is this what you want?这是你想要的吗? 在此处输入图像描述

java Code as below: java 代码如下:

public class TestActivity extends AppCompatActivity {


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test_activity);
    RecyclerView recyclerView = findViewById(R.id.recyclerview);
    GridLayoutManager layoutManager = new GridLayoutManager(this, 5, GridLayoutManager.VERTICAL, true);
    recyclerView.setLayoutManager(layoutManager);

    List<String> datas = new ArrayList<>();
    for (int i = 0; i < 48; i++) {
        datas.add("item:" + (i + 1));
    }
    recyclerView.setAdapter(new MyAdapter(this, datas));
}


public static class MyAdapter extends RecyclerView.Adapter<ViewHolder> {


    private final Context context;

    private List<String> datas;

    public MyAdapter(Context context, List<String> datas) {
        this.context = context;
        this.datas = datas;
    }

    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        return new ViewHolder(new TextView(context));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.textView.setText(datas.get(position));
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }
}

public static class ViewHolder extends RecyclerView.ViewHolder {

    TextView textView;

    public ViewHolder(@NonNull @NotNull View itemView) {
        super(itemView);
        textView = (TextView) itemView;
    }
}

} }

layout file:布局文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layoutDirection="rtl">

</androidx.recyclerview.widget.RecyclerView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java中从底部到顶部的布局,具有动态大小调整 - Bottom-to-top layout in Java with dynamic sizing Android RecyclerView LayoutManager异常 - Android RecyclerView LayoutManager Exception RecyclerView没有LayoutManager android.support.v7.widget.RecyclerView - RecyclerView has no LayoutManager android.support.v7.widget.RecyclerView &#39;布尔android.support.v7.widget.RecyclerView $ LayoutManager.canScrollVertically()&#39; - 'boolean android.support.v7.widget.RecyclerView$LayoutManager.canScrollVertically()' Recyclerview - 从下到上重叠项目 - Recyclerview - Overlap items bottom to top Android recyclerview 滚动到顶部 - Android recyclerview scroll to top 如何在 Recyclerview/Layoutmanager 中获取 Scrollposition? - How to get the Scrollposition in the Recyclerview/Layoutmanager? 为片段创建RecyclerView时LayoutManager和RecyclerView问题 - LayoutManager and RecyclerView Issues When Creating RecyclerView For Fragment 尝试调用虚方法 &#39;void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager - Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager android.view.InflateException:二进制XML文件第2行:RecyclerView没有LayoutManager - android.view.InflateException: Binary XML file line #2: RecyclerView has no LayoutManager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM