最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android入門之TableLayout應(yīng)用解析(二)

 更新時間:2014年08月08日 10:13:07   投稿:shichen2014  
這篇文章主要介紹了Android入門之TableLayout應(yīng)用,需要的朋友可以參考下

本文在上一篇初步介紹TableLayout常用屬性的基礎(chǔ)上,將進一步介紹如何UI設(shè)計器設(shè)計TableLayout + TableRow。由于實際應(yīng)用中,經(jīng)常需要在代碼里往TableLayout添加數(shù)據(jù)(9宮圖也可以用TableLayout做出來 ),本文就是介紹這方面的簡單使用方法。

main.xml的代碼如下,用到TableLayout的ID為TableLayout01:

<?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的實例
    TableLayout tableLayout = (TableLayout)findViewById(R.id.TableLayout01);
    //全部列自動填充空白處
    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é)果如下圖:

相關(guān)文章

最新評論

长沙县| 堆龙德庆县| 象州县| 广汉市| 博乐市| 鄂托克前旗| 潞西市| 夹江县| 长葛市| 方山县| 柘城县| 游戏| 勐海县| 韶关市| 安新县| 长顺县| 会宁县| 东阳市| 平利县| 漳平市| 海口市| 西林县| 天津市| 丽水市| 安庆市| 会昌县| 方城县| 赫章县| 白山市| 牡丹江市| 南和县| 义马市| 景谷| 房产| 永善县| 府谷县| 新邵县| 兰溪市| 寿阳县| 乌鲁木齐县| 五寨县|