Android入門(mén)之TableLayout應(yīng)用解析(二)
本文在上一篇初步介紹TableLayout常用屬性的基礎(chǔ)上,將進(jìn)一步介紹如何UI設(shè)計(jì)器設(shè)計(jì)TableLayout + TableRow。由于實(shí)際應(yīng)用中,經(jīng)常需要在代碼里往TableLayout添加數(shù)據(jù)(9宮圖也可以用TableLayout做出來(lái) ),本文就是介紹這方面的簡(jiǎn)單使用方法。
main.xml的代碼如下,用到TableLayout的ID為T(mén)ableLayout01:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content"> </TableLayout> </LinearLayout>
JAVA代碼部分如下:
package com.LayoutDemo; import com.LayoutDemo.R; import android.app.Activity; import android.os.Bundle; import android.view.ViewGroup; import android.widget.TableLayout; import android.widget.TableRow; import android.widget.TextView; public class LayoutDemo extends Activity { /** Called when the activity is first created. */ private final int WC = ViewGroup.LayoutParams.WRAP_CONTENT; private final int FP = ViewGroup.LayoutParams.FILL_PARENT; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //新建TableLayout01的實(shí)例 TableLayout tableLayout = (TableLayout)findViewById(R.id.TableLayout01); //全部列自動(dòng)填充空白處 tableLayout.setStretchAllColumns(true); //生成10行,8列的表格 for(int row=0;row<10;row++) { TableRow tableRow=new TableRow(this); for(int col=0;col<8;col++) { //tv用于顯示 TextView tv=new TextView(this); tv.setText("("+col+","+row+")"); tableRow.addView(tv); } //新建的TableRow添加到TableLayout tableLayout.addView(tableRow, new TableLayout.LayoutParams(FP, WC)); } } }
結(jié)果如下圖:
- Android TabLayout(選項(xiàng)卡布局)簡(jiǎn)單用法實(shí)例分析
- ExtJS擴(kuò)展 垂直tabLayout實(shí)現(xiàn)代碼
- jQuery EasyUI 中文API Layout(Tabs)
- Android開(kāi)發(fā)筆記 TableLayout常用的屬性介紹
- Android入門(mén)之TableLayout應(yīng)用解析(一)
- Android TableLayout數(shù)據(jù)列表的回顯清空實(shí)現(xiàn)思路及代碼
- Android布局(RelativeLayout、TableLayout等)使用方法
- Android布局之TableLayout表格布局
- Android開(kāi)發(fā)之TableLayout表格布局
- android TabLayout使用方法詳解
相關(guān)文章
Android 下載并打開(kāi)PDF,Doc,Dwg文檔實(shí)例
本篇文章主要介紹了Android 下載并打開(kāi)PDF,Doc,Dwg文檔實(shí)例,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-04-04Android手機(jī)衛(wèi)士之確認(rèn)密碼對(duì)話框
這篇文章主要為大家詳細(xì)介紹了Android手機(jī)衛(wèi)士之確認(rèn)密碼對(duì)話框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10關(guān)于Android Studio封裝SDK的那些事兒
這篇文章主要給大家介紹了關(guān)于Android Studio封裝SDK的那些事兒,文中通過(guò)圖文以及示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-09-09Flutter交互并使用小工具管理其狀態(tài)widget的state詳解
這篇文章主要為大家介紹了Flutter交互并使用小工具管理其狀態(tài)widget的state詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12NestScrollView嵌套R(shí)ecyclerView實(shí)現(xiàn)淘寶首頁(yè)滑動(dòng)效果
這篇文章主要介紹了NestScrollView嵌套R(shí)ecyclerView實(shí)現(xiàn)淘寶首頁(yè)滑動(dòng)效果,主要實(shí)現(xiàn)淘寶首頁(yè)嵌套滑動(dòng),中間tab吸頂效果,以及介紹NestScrollView嵌套R(shí)ecyclerView處理滑動(dòng)沖突的方法,需要的朋友可以參考下2021-12-12Android實(shí)現(xiàn)畫(huà)中畫(huà)功能(圖片)
畫(huà)中畫(huà)是一種特殊類(lèi)型的多窗口模式,最常用于視頻播放。這篇文章主要介紹了Android實(shí)現(xiàn)畫(huà)中畫(huà)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08Android ActionBar制作時(shí)鐘實(shí)例解析
這篇文章主要為大家詳細(xì)介紹了Android ActionBar制作時(shí)鐘的實(shí)現(xiàn)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-05-05