当前位置:   article > 正文

Android使用RecyclerView绘制表格_android recyclerview 表格线

android recyclerview 表格线

一、效果图

效果图

二、创建步骤:

思路:其实就是将MainActivity中写好表头布局,同时和RecyclerView的Item布局保持一致,这里面列之间使用View进行分割,边框使用layer-list和shape实现。

1:MainActivity代码:

public class MainActivity extends AppCompatActivity {
   
    private RecyclerView rv_sheet;
    private List<entity> list;
    private SheetAdapter sheetAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //数据,一般从后台通过网络请求到
        list = new ArrayList<entity>();
        for (int i = 0; i < 30; i++) {
            list.add(new entity("Wade", "James", "Kobe"));
        }


        rv_sheet = (RecyclerView) findViewById(R.id.rv_sheet);
        //设置线性布局 Creates a vertical LinearLayoutManager
        rv_sheet.setLayoutManager(new LinearLayoutManager(this));
        //设置recyclerView每个item间的分割线
        rv_sheet.addItemDecoration(new DividerItemDecoration(this,
                DividerItemDecoration.VERTICAL_LIST));
        //创建recyclerView的实例,并将数据传输到适配器
        sheetAdapter = new SheetAdapter(list);

        rv_sheet.setAdapter(sheetAdapter);

    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

2、MainActivity布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:orientation="vertical"
    tools:context=".MainActivity"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawa
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/286622
推荐阅读
相关标签
  

闽ICP备14008679号