MyDemo.java
package com.jackie.tablelayout;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class MainActivity extends Activity {
private String titleData[][]=new String[][]{
{"ID","姓名","EMALL","地址"},
{"MLDN","魔乐科技","Jackiewang@qq.com",
"科技园创维中心二楼的食堂"},
{"jackie","莫勒科技","291866706@qq.com","深圳"}};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TableLayout layout=new TableLayout(this);
TableLayout.LayoutParams layoutParam=new TableLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
layout.setBackgroundResource(R.drawable.rabbit);
for(int x=0;x<this.titleData.length;x++){
TableRow row=new TableRow(this);
for(int y=0;y<this.titleData[x].length;y++){
TextView text=new TextView(this);
text.setText(this.titleData[x][y]);
row.addView(text,y);
}
layout.addView(row);
}
super.setContentView(layout,layoutParam);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.ViewGroup;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
public class MainActivity extends Activity {
private String titleData[][]=new String[][]{
{"ID","姓名","EMALL","地址"},
{"MLDN","魔乐科技","Jackiewang@qq.com",
"科技园创维中心二楼的食堂"},
{"jackie","莫勒科技","291866706@qq.com","深圳"}};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TableLayout layout=new TableLayout(this);
TableLayout.LayoutParams layoutParam=new TableLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);
layout.setBackgroundResource(R.drawable.rabbit);
for(int x=0;x<this.titleData.length;x++){
TableRow row=new TableRow(this);
for(int y=0;y<this.titleData[x].length;y++){
TextView text=new TextView(this);
text.setText(this.titleData[x][y]);
row.addView(text,y);
}
layout.addView(row);
}
super.setContentView(layout,layoutParam);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
main.xml
<TableLayout 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"
android:orientation="vertical"
android:shrinkColumns="3"
android:collapseColumns="0,3"
android:background="@drawable/mm"
tools:context=".MainActivity" >
<TableRow>
<TextView
android:layout_column="0"
android:gravity="center_horizontal"
android:padding="8px"
android:text="ID" />
<TextView
android:layout_column="1"
android:gravity="center_horizontal"
android:padding="8px"
android:text="姓名" />
<TextView
android:layout_column="2"
android:gravity="center_horizontal"
android:padding="8px"
android:text="EMALL" />
<TextView
android:layout_column="3"
android:gravity="center_horizontal"
android:padding="8px"
android:text="地址" />
</TableRow>
<View
android:layout_height="2px"
android:background="#FF909090"/>
<TableRow>
<TextView
android:layout_column="0"
android:gravity="center_horizontal"
android:padding="3px"
android:text="MLDN" />
<TextView
android:layout_column="1"
android:gravity="center_horizontal"
android:padding="3px"
android:text="魔乐科技" />
<TextView
android:layout_column="2"
android:gravity="center_horizontal"
android:padding="3px"
android:text="Jackiewang@qq.com" />
<TextView
android:layout_column="3"
android:gravity="center_horizontal"
android:padding="3px"
android:text="科技园创维中心二楼的食堂" />
</TableRow>
<TableRow>
<TextView
android:layout_column="0"
android:gravity="center_horizontal"
android:padding="3px"
android:text="jackie" />
<TextView
android:layout_column="1"
android:gravity="center_horizontal"
android:padding="3px"
android:text="凡趣科技" />
<TextView
android:layout_column="2"
android:gravity="center_horizontal"
android:padding="3px"
android:text="291866706@qq.com" />
<TextView
android:layout_column="3"
android:gravity="center_horizontal"
android:padding="3px"
android:text="深圳" />
</TableRow>
</TableLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:shrinkColumns="3"
android:collapseColumns="0,3"
android:background="@drawable/mm"
tools:context=".MainActivity" >
<TableRow>
<TextView
android:layout_column="0"
android:gravity="center_horizontal"
android:padding="8px"
android:text="ID" />
<TextView
android:layout_column="1"
android:gravity="center_horizontal"
android:padding="8px"
android:text="姓名" />
<TextView
android:layout_column="2"
android:gravity="center_horizontal"
android:padding="8px"
android:text="EMALL" />
<TextView
android:layout_column="3"
android:gravity="center_horizontal"
android:padding="8px"
android:text="地址" />
</TableRow>
<View
android:layout_height="2px"
android:background="#FF909090"/>
<TableRow>
<TextView
android:layout_column="0"
android:gravity="center_horizontal"
android:padding="3px"
android:text="MLDN" />
<TextView
android:layout_column="1"
android:gravity="center_horizontal"
android:padding="3px"
android:text="魔乐科技" />
<TextView
android:layout_column="2"
android:gravity="center_horizontal"
android:padding="3px"
android:text="Jackiewang@qq.com" />
<TextView
android:layout_column="3"
android:gravity="center_horizontal"
android:padding="3px"
android:text="科技园创维中心二楼的食堂" />
</TableRow>
<TableRow>
<TextView
android:layout_column="0"
android:gravity="center_horizontal"
android:padding="3px"
android:text="jackie" />
<TextView
android:layout_column="1"
android:gravity="center_horizontal"
android:padding="3px"
android:text="凡趣科技" />
<TextView
android:layout_column="2"
android:gravity="center_horizontal"
android:padding="3px"
android:text="291866706@qq.com" />
<TextView
android:layout_column="3"
android:gravity="center_horizontal"
android:padding="3px"
android:text="深圳" />
</TableRow>
</TableLayout>