Reputation:
I want to make such kind of table(as shown in the picture) for my android application. But i can't figure it out. How can i do it? Please give me some sample example or tricks that will help me to do this table.
Upvotes: 0
Views: 95
Reputation: 10887
Layout which you are expected can be obtained with LinearLayout
with attributes layout_weight
also. But as you are more familiar with TableLayout
.
TableLayout:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:shrinkColumns="2"
android:stretchColumns="2" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text1" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Text2" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Text3" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Text4" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/black"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Text5" />
</LinearLayout>
</TableRow>
</TableLayout>
One two Tablerows
are displayed as per SO Layout, you can take further long from here.
Upvotes: 1
Reputation: 6736
its quite simple. the android:layout-weight
property should do the job.
but you also need the borders so we have to create a drawable to set the background for TextView
s inside /res/drawable folder :
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="2dp"
android:color="#000" />
</shape>
and here is the activity's xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/bg"
android:gravity="center"
android:text="@string/hello_world" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
and this is how it looks:
Hope its what you wanted ;)
Upvotes: 0
Reputation: 689
You can use tablelayout. See this example http://www.mkyong.com/android/android-tablelayout-example/
Upvotes: 0