Untuk dapat membuat Tabel, diperlukan komponen TableLayout dan TableRow. Dalam contoh berikut, isi dari table saya gunakan TextView.
Script XML
<LinearLayout 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">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:text="Baris 1, Kolom 1"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:text="Baris 1, Kolom 2"
android:gravity="center"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:background="#fff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:text="Baris 2, Kolom 1"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="10dp"
android:text="Baris 2, Kolom 2"
android:gravity="center"/>
</TableRow>
</TableLayout>
</LinearLayout>
Script java
package com.thegunk.table;Jika dijalankan
import android.os.Bundle;
import android.app.Activity;
public class TableActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_table);
}
}
EmoticonEmoticon