Reputation: 41
I try to make a table in my Android app with cells like this:
(sorry for this link, I can't attach images due to low reputation)
My idea was to use a linear layout in a table row, but is not working correct. Please, if you have any idea about how to modify the table layout to work as I expect - give me any idea.
My xml code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@color/black"
android:orientation="vertical" >
<TableLayout
style="@style/TextColor"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="90"
android:stretchColumns="1"
android:textColor="@colors/white" >
<TableRow>
<TextView
style="@style/TextColor"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/cell"
android:gravity="center"
android:padding="10dip"
android:singleLine="false"
android:text="@string/start_time" />
<TextView
style="@style/TextColor"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/cell"
android:gravity="center"
android:padding="10dip"
android:text="@string/start_time" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
style="@style/TextColor"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/cell"
android:gravity="center"
android:padding="10dip"
android:text="@string/start_time" />
<TextView
style="@style/TextColor"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/cell"
android:gravity="center"
android:padding="10dip"
android:text="@string/start_time" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
style="@style/TextColor"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/cell"
android:gravity="center"
android:padding="10dip"
android:text="@string/start_time" />
<TextView
style="@style/TextColor"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@drawable/cell"
android:gravity="center"
android:padding="10dip"
android:text="@string/start_time" />
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
</TableLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="10"
android:gravity="center"
android:text="ADDS" />
</LinearLayout>
EDIT I made some changes according to your comments. Please, take a look and tell me please, why the text is not displayed?
<LinearLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@color/black"
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/black"
android:orientation="horizontal"
android:baselineAligned="false" >
<LinearLayout
android:layout_weight=".5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/cell"
android:orientation="vertical" >
<TextView
android:layout_height="fill_parent"
style="@style/TextColor"
android:gravity="center"
android:padding="10dip"
android:text="@string/start_time" />
<TextView
style="@style/TextColor"
android:gravity="center"
android:padding="10dip"
android:text="@string/activate" />
</LinearLayout>
<LinearLayout
android:layout_weight=".5"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:background="@drawable/cell"
android:orientation="vertical" >
<TextView
android:layout_height="fill_parent"
style="@style/TextColor"
android:gravity="center"
android:padding="10dip"
android:text="@string/start_time" />
<TextView
style="@style/TextColor"
android:gravity="center"
android:padding="10dip"
android:text="@string/activate" />
</LinearLayout>
</LinearLayout>
Upvotes: 0
Views: 5934
Reputation: 41
Thank you for your help. I got an solution for my purpose. My xml file looks like this now:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/black"
android:orientation="horizontal"
android:baselineAligned="false" >
<LinearLayout
android:layout_weight=".5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/cell"
android:orientation="vertical" >
<TextView
style="@style/TextColor"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:padding="10dip"
android:textSize="46sp"
android:text="@string/start_time" />
<TextView
style="@style/TextColor"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:padding="10dip"
android:paddingBottom="@dimen/zero"
android:text="@string/activate" />
</LinearLayout>
<LinearLayout
android:layout_weight=".5"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:background="@drawable/cell"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@style/TextColor"
android:gravity="center"
android:padding="10dip"
android:textSize="46sp"
android:text="@string/start_time" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@style/TextColor"
android:gravity="center"
android:padding="10dip"
android:text="@string/activate" />
</LinearLayout>
Upvotes: 1
Reputation: 2451
For border place this in a file named border.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#00000000"/>
<stroke android:width="1dp" android:color="#000000"/>
</shape>
And to draw the inside content use this
<LinearLayout
android:layout_margin="5dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/border">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:text="Sample Text"/>
<TextView
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="11sp"
android:text="Sample Text"/>
You can use the LinearLayout
inside your TableRow
or anywhere you want
Upvotes: 0
Reputation: 12530
Try this.
<TableRow
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:orientation="vertical"
android:id="@+id/row">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/container">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:paddingLeft="20dp"
android:id="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/textView2"
android:layout_centerVertical="true"
android:layout_alignRight="@+id/textView"
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:layout_alignEnd="@+id/textView" />
</LinearLayout>
</TableRow>
Upvotes: 0