Skip to content

Instantly share code, notes, and snippets.

@codingwithsara
Created September 20, 2020 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingwithsara/1f517cd97e2f842de24c0089d79654c9 to your computer and use it in GitHub Desktop.
Save codingwithsara/1f517cd97e2f842de24c0089d79654c9 to your computer and use it in GitHub Desktop.
【Android Studio Tips】TableLayout – Border & Collapse –
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#ffffff"
tools:context=".MainActivity">
<TableLayout
android:id="@+id/table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="30dp"
android:layout_marginHorizontal="10dp"
android:background="#f1f1f1"
android:collapseColumns="1,2">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textStyle="bold"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textStyle="bold"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tel"
android:textStyle="bold"
android:layout_weight="1"
android:gravity="center"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Alice"
android:layout_weight="1"
android:gravity="center"
android:background="#ffffff"
android:layout_marginBottom="1dp"
android:layout_marginHorizontal="1dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="a@a.com"
android:layout_weight="1"
android:gravity="center"
android:background="#ffffff"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="111-111"
android:layout_weight="1"
android:gravity="center"
android:background="#ffffff"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bob"
android:layout_weight="1"
android:gravity="center"
android:background="#ffffff"
android:layout_marginBottom="1dp"
android:layout_marginHorizontal="1dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="b@b.com"
android:layout_weight="1"
android:gravity="center"
android:background="#ffffff"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="222-222"
android:layout_weight="1"
android:gravity="center"
android:background="#ffffff"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Carey"
android:layout_weight="1"
android:gravity="center"
android:background="#ffffff"
android:layout_marginBottom="1dp"
android:layout_marginHorizontal="1dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="c@c.com"
android:layout_weight="1"
android:gravity="center"
android:background="#ffffff"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="333-333"
android:layout_weight="1"
android:gravity="center"
android:background="#ffffff"
android:layout_marginRight="1dp"
android:layout_marginBottom="1dp"/>
</TableRow>
</TableLayout>
<Button
android:id="@+id/switchBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Detail"
android:textAllCaps="false"
android:layout_gravity="center"
android:onClick="collapseTable"/>
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment