Here some basic tutorials how to creating table layout in android. This is first part creating table layout from xml layout next tutorials from programmatically . keep visiting .
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="@+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="6"
android:gravity="center"
android:text="Weather Report"
android:textSize="18dp"
android:textStyle="bold" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView21"
android:text="" >
</TextView>
<TextView
android:id="@+id/TextView22"
android:gravity="center"
android:text="M"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/TextView23"
android:gravity="center"
android:text="T"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/TextView24"
android:gravity="center"
android:text="W"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/TextView25"
android:gravity="center"
android:text="T"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/textView26"
android:gravity="center"
android:text="F"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView31"
android:text="Day High"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView32"
android:gravity="center_horizontal"
android:text="34°C" >
</TextView>
<TextView
android:id="@+id/textView33"
android:gravity="center_horizontal"
android:text="35°C" >
</TextView>
<TextView
android:id="@+id/textView34"
android:gravity="center_horizontal"
android:text="34°C" >
</TextView>
<TextView
android:id="@+id/textView35"
android:gravity="center_horizontal"
android:text="35°C" >
</TextView>
<TextView
android:id="@+id/textView36"
android:gravity="center_horizontal"
android:text="33°C" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView41"
android:text="Day Low"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView42"
android:gravity="center_horizontal"
android:text="28°C" >
</TextView>
<TextView
android:id="@+id/textView43"
android:gravity="center_horizontal"
android:text="27°C" >
</TextView>
<TextView
android:id="@+id/textView44"
android:gravity="center_horizontal"
android:text="29°C" >
</TextView>
<TextView
android:id="@+id/textView45"
android:gravity="center_horizontal"
android:text="26°C" >
</TextView>
<TextView
android:id="@+id/textView46"
android:gravity="center_horizontal"
android:text="29°C" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="@+id/textView8"
android:text="Conditions"
android:textStyle="bold" >
</TextView>
<ImageView
android:id="@+id/imageView1"
android:src="@drawable/monday" >
</ImageView>
<ImageView
android:id="@+id/imageView2"
android:src="@drawable/tuesday" >
</ImageView>
<ImageView
android:id="@+id/imageView3"
android:src="@drawable/wednesday" >
</ImageView>
<ImageView
android:id="@+id/imageView4"
android:src="@drawable/thursday" >
</ImageView>
<ImageView
android:id="@+id/imageView5"
android:src="@drawable/friday" >
</ImageView>
</TableRow>
</TableLayout>
How to call in java file in Activity is simple, Like this:
public class TableLayoutExampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Output Looks Like:
Thank you , for visiting.
Happy Coding!!!
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="@+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="6"
android:gravity="center"
android:text="Weather Report"
android:textSize="18dp"
android:textStyle="bold" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/TextView21"
android:text="" >
</TextView>
<TextView
android:id="@+id/TextView22"
android:gravity="center"
android:text="M"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/TextView23"
android:gravity="center"
android:text="T"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/TextView24"
android:gravity="center"
android:text="W"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/TextView25"
android:gravity="center"
android:text="T"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="@+id/textView26"
android:gravity="center"
android:text="F"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView31"
android:text="Day High"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView32"
android:gravity="center_horizontal"
android:text="34°C" >
</TextView>
<TextView
android:id="@+id/textView33"
android:gravity="center_horizontal"
android:text="35°C" >
</TextView>
<TextView
android:id="@+id/textView34"
android:gravity="center_horizontal"
android:text="34°C" >
</TextView>
<TextView
android:id="@+id/textView35"
android:gravity="center_horizontal"
android:text="35°C" >
</TextView>
<TextView
android:id="@+id/textView36"
android:gravity="center_horizontal"
android:text="33°C" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView41"
android:text="Day Low"
android:textStyle="bold" >
</TextView>
<TextView
android:id="@+id/textView42"
android:gravity="center_horizontal"
android:text="28°C" >
</TextView>
<TextView
android:id="@+id/textView43"
android:gravity="center_horizontal"
android:text="27°C" >
</TextView>
<TextView
android:id="@+id/textView44"
android:gravity="center_horizontal"
android:text="29°C" >
</TextView>
<TextView
android:id="@+id/textView45"
android:gravity="center_horizontal"
android:text="26°C" >
</TextView>
<TextView
android:id="@+id/textView46"
android:gravity="center_horizontal"
android:text="29°C" >
</TextView>
</TableRow>
<TableRow
android:id="@+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="@+id/textView8"
android:text="Conditions"
android:textStyle="bold" >
</TextView>
<ImageView
android:id="@+id/imageView1"
android:src="@drawable/monday" >
</ImageView>
<ImageView
android:id="@+id/imageView2"
android:src="@drawable/tuesday" >
</ImageView>
<ImageView
android:id="@+id/imageView3"
android:src="@drawable/wednesday" >
</ImageView>
<ImageView
android:id="@+id/imageView4"
android:src="@drawable/thursday" >
</ImageView>
<ImageView
android:id="@+id/imageView5"
android:src="@drawable/friday" >
</ImageView>
</TableRow>
</TableLayout>
How to call in java file in Activity is simple, Like this:
public class TableLayoutExampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Output Looks Like:
Thank you , for visiting.
Happy Coding!!!
No comments:
Post a Comment