成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Android中怎么通過自定義LayoutManager實現(xiàn)花式表格-創(chuàng)新互聯(lián)

本篇文章為大家展示了Android中怎么通過自定義LayoutManager實現(xiàn)花式表格,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

龍陵ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!

TableView具有如下特點:

支持不規(guī)則表格同時支持橫向和縱向滾動支持頂部和左側懸浮基于RecyclerView,所以RecyclerView自定義子視圖、高效回收、子視圖多樣性這些特點它都有沒有多層RecyclerView嵌套,性能更棒

Github地址

使用

第一步 | 添加xml文件

<?xml version="1.0" encoding="utf-8"?><FrameLayout 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" tools:context=".ui.fragment.table.TableFragment"> <com.orient.me.widget.rv.adapter.TableView android:id="@+id/tb" android:layout_width="match_parent" android:layout_height="match_parent"/></FrameLayout>

第二步 | 獲取TableView

在展示代碼之前,了解一下TableView中的主要函數(shù):

這個setTitle(boolean isLeftOpen, boolean isTopOpen)有什么作用呢?為了確保表格的每一個單元格的長度和寬度都一樣(子視圖可以在橫縱方向上占有多個單元格),寬和高都使用兩種方式:

設置具體的值,那么單元格的寬或者高的值就是具體的設置一行或者一列可以容納的單元格數(shù)量

所以寬高各有兩種,模式的數(shù)量 = 2 * 2,總共有:

代碼:

// if use butterknife// or use findViewById@BindView(R.id.tb) TableView mTable;// 默認為 TableLayoutManager.MODE_A, 4, 8mTable.setModeAndValue(TableLayoutManager.MODE_A, 6, 8);

第三步 | 創(chuàng)建數(shù)據(jù)類

實現(xiàn)ICellItem接口:

public class TableCell implements ICellItem { private String name; private String value; private int type; private int row; private int col; private int widthSpan; private int heightSpan; //... 省略構造函數(shù)和Get Set方法 @Override public int getRow() { return row; } @Override public int getCol() { return col; } @Override public int getWidthSpan() { return widthSpan; } @Override public int getHeightSpan() { return heightSpan; }}

第四步 | 設置適配器

private TableAdapter<TableCell> mAdapter;protected void initWidget(View root) { // 假設在這個方法中初始化 mTable.setAdapter(mAdapter = new TableAdapter<TableCell>(new ArrayList<>()) { @Override public int getItemLayout(TableCell tableCell, int pos) {  // ... 返回子視圖布局文件  // 支持多類型  return R.layout.table_cell_content_item; } @Override public BaseAdapter.ViewHolder<TableCell> onCreateViewHolder(View root, int itemType) {  // itemType是子視圖布局文件  // 根據(jù)布局返回具體的ViewHolder  return new ContentHolder(root); } });}// 具體的ViewHolderclass ContentHolder extends BaseAdapter.ViewHolder<TableCell>{ TextView mContent; public ContentHolder(View itemView) {  super(itemView);  mContent = itemView.findViewById(R.id.tv_name); } @Override protected void onBind(TableCell tableCell) {  mContent.setText(tableCell.getValue()); } }

第五步 | 重新測繪

如果TableView使用的模式是Mode_A、Mode_CMode_D,需要再重新測量:

mTable.post(() -> mTable.reMeasure());

上述內(nèi)容就是Android中怎么通過自定義LayoutManager實現(xiàn)花式表格,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

標題名稱:Android中怎么通過自定義LayoutManager實現(xiàn)花式表格-創(chuàng)新互聯(lián)
文章來源:http://jinyejixie.com/article34/ccjhse.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、App設計做網(wǎng)站、虛擬主機、域名注冊小程序開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名