<del id="d4fwx"><form id="d4fwx"></form></del>
      <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

            <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
          • Android中怎么通過自定義LayoutManager實(shí)現(xiàn)花式表格

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

            創(chuàng)新互聯(lián)公司專注于敖漢企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站設(shè)計(jì),商城網(wǎng)站定制開發(fā)。敖漢網(wǎng)站建設(shè)公司,為敖漢等地區(qū)提供建站服務(wù)。全流程按需網(wǎng)站建設(shè),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)

            TableView具有如下特點(diǎn):

            支持不規(guī)則表格同時支持橫向和縱向滾動支持頂部和左側(cè)懸浮基于RecyclerView,所以RecyclerView自定義子視圖、高效回收、子視圖多樣性這些特點(diǎn)它都有沒有多層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è)置一行或者一列可以容納的單元格數(shù)量

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

            代碼:

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

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

            實(shí)現(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; //... 省略構(gòu)造函數(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; }}

            第四步 | 設(shè)置適配器

            private TableAdapter<TableCell> mAdapter;protected void initWidget(View root) { // 假設(shè)在這個方法中初始化 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_AMode_CMode_D,需要再重新測量:

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

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

            本文標(biāo)題:Android中怎么通過自定義LayoutManager實(shí)現(xiàn)花式表格
            鏈接分享:http://www.jbt999.com/article10/ijjigo.html

            成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、外貿(mào)建站、ChatGPT關(guān)鍵詞優(yōu)化、移動網(wǎng)站建設(shè)網(wǎng)站制作

            廣告

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

            網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司

              <del id="d4fwx"><form id="d4fwx"></form></del>
              <del id="d4fwx"><form id="d4fwx"></form></del><del id="d4fwx"><form id="d4fwx"></form></del>

                    <code id="d4fwx"><abbr id="d4fwx"></abbr></code>
                  • 大香焦在线999 | 国产视频福利在线看 | 国产精品无码在线观看视频 | 91成人做爰A片无遮挡直播 | 天堂成人在线 |