【Android开发学习24】界面布局之表格布局TableLayout+TableRow...

【Android开发学习24】界面布局之表格布局TableLayout+TableRow...

2023年7月15日发(作者:)

【Android开发学习24】界⾯布局之表格布局TableLayout+TableRow⼀、基础知识:

TableLayout置底,TableRow在TableLayout的上⾯,⽽Button、TextView等控件就在TableRow之上,另外,TableLayout之上也可以单独放控件。TableLayout是⼀个使⽤复杂的布局,最简单的⽤法就仅仅是拖拉控件做出个界⾯,但实际上,会经常在代码⾥使⽤TableLayout,例如做出表格的效果。

android:collapseColumns:以第0⾏为序,隐藏指定的列android:shrinkColumns:以第0⾏为序,⾃动延伸指定的列填充可⽤部分android:stretchColumns:以第0⾏为序,尽量把指定的列填充空⽩部分

⼆、⽅案⼀代码展⽰:⽅案⼀采⽤xml布局,在代码中除了显⽰layout之外,未作任何布局相关的操作。1."Acticity_06srcyanacticity_"package ty_06;import ;import ty;public class MainActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

te(savedInstanceState);

setContentView(ty_main);

}}

2."Activity_06reslayoutactivity_"

三、⽅案⼆代码展⽰:⽅案⼆采⽤代码布局,在layout⽂件中除了显⽰⼀个空的TabLayout之外,未作任何其它布局。1."Acticity_06srcyanacticity_"package ty_06;import ;import oup;import ayout;import ow;import ew;import ty;public class MainActivity extends Activity { /** Called when the activity is first created. */

private final int WC = _CONTENT;

private final int FP = _PARENT;

@Override

public void onCreate(Bundle savedInstanceState) {

te(savedInstanceState);

setContentView(ty_main);

//新建TableLayout01的实例

TableLayout tableLayout = (TableLayout)findViewById(ayout01);

//全部列⾃动填充空⽩处

etchAllColumns(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);

t("("+col+","+row+")");

w(tv);

}

//新建的TableRow添加到TableLayout

w(tableRow, new Params(FP, WC));

}

}}2."Activity_06reslayoutactivity_"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:id="@+id/TableLayout01"

android:layout_width="fill_parent"

android:layout_height="wrap_content">

三、效果展⽰:1.⽅案⼀:

2.⽅案⼆:

发布者:admin,转转请注明出处:http://www.yc00.com/web/1689425684a246214.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信