7 Table Layout
Algorithm:
Step 1) Create a new Android Studio Project
Step 2)Goto Project Structure and open activity_main.xml file
Step 3) Remove the default layout i.e Constraint layout and create TableLayout by using tag or drag and drop from the palette.
Step 3) Create TextViews or ImageViews by using tags in sctivity_main.xml file or drag and drop from the palette.
Step 4) Add Image to the res/drawable folder and supported filenames are lowercase and _ names are allowed. Ex: klu_thins.jpg
Step 5) Run the application from the menu bar select Run and Click on Run App option.
Program:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" >
<TableRow>
<TextView android:id="@+id/textView1"
android:layout_width="wrap_content" android:layout_height="30dp" android:text="Column1" android:background="@color/colorAccent"/>
<TextView android:id="@+id/textView2"
android:layout_width="wrap_content" android:layout_height="30dp" android:text="Column2" android:background="@color/colorPrimaryDark"/>
</TableRow>
<TableRow>
<TextView android:id="@+id/textView3"
android:layout_width="wrap_content" android:layout_height="30dp" android:text="Column1" android:background="#FFFFD940"/>
<TextView android:id="@+id/textView4"
android:layout_width="wrap_content" android:layout_height="30dp" android:text="Column2"
android:background="@color/colorAccent"/> </TableRow>
</TableLayout>
MainActivity.java
package com.example.tablelayout;
import android.support.v7.app.AppCompatActivity; import android.os.Bundle;
public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
}
OUTPUT:
Comments
Post a Comment