tablelayout not having equal width - android

I am using this code, but the center column is having more width than others. i tried removing rows, it seems the problem is row2 & row4. but there is no padding or margin but still its not proper.
<!-- title row 1 -->
<TableRow>
<TextView
android:id="#+id/timeLabletv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="3dp"
android:text="#string/tr_time_spend"
android:textColor="#FFFFFF"
android:textSize="8sp"
android:textStyle="bold" />
<TextView
android:id="#+id/focusLabletv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="3dp"
android:text="#string/tr_focus"
android:textColor="#FFFFFF"
android:textSize="8sp"
android:textStyle="bold" />
<TextView
android:id="#+id/caloriesLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="3dp"
android:text="#string/tr_calories"
android:textColor="#FFFFFF"
android:textSize="8sp"
android:textStyle="bold" />
</TableRow>
<!-- data row 1 -->
<TableRow>
<TextView
android:id="#+id/timeSpenttv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:text="8.00M"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/focusValuetv"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:text="#string/tr_focus_balance"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/caloriestv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:text="#string/tr_calories_def"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
</TableRow>
<!-- title row 2 -->
<TableRow>
<TextView
android:id="#+id/setsLabletv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="3dp"
android:text="#string/tr_sets"
android:textColor="#FFFFFF"
android:textSize="8sp"
android:textStyle="bold" />
<TextView
android:id="#+id/repetitionsLabletv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="3dp"
android:text="#string/tr_reps"
android:textColor="#FFFFFF"
android:textSize="8sp"
android:textStyle="bold" />
<TextView
android:id="#+id/kilosLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="3dp"
android:text="#string/tr_kilos"
android:textColor="#FFFFFF"
android:textSize="8sp"
android:textStyle="bold" />
</TableRow>
<!-- data row 2 -->
<TableRow>
<TextView
android:id="#+id/setsValuetv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:text="#string/tr_sets_def"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/repetitionsValuetv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:text="#string/tr_reps_def"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/kilostv"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:text="#string/tr_kilos_def"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
it looks like this:

You can set the field widths to 0 and the weights to "1" and it sets all three columns to equal widths. Like this:
<TableRow>
<TextView
android:id="#+id/timeLabletv"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="3dp"
android:text="#string/tr_time_spend"
android:textColor="#ffffff"
android:textSize="8sp"
android:textStyle="bold" />
<TextView
android:id="#+id/focusLabletv"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="3dp"
android:text="#string/tr_focus"
android:textColor="#ffffff"
android:textSize="8sp"
android:textStyle="bold" />
<TextView
android:id="#+id/caloriesLabel"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="3dp"
android:text="#string/tr_calories"
android:textColor="#ffffff"
android:textSize="8sp"
android:textStyle="bold" />
</TableRow>
<!-- data row 1 -->
<TableRow>
<TextView
android:id="#+id/timeSpenttv"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:text="8.00M"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/focusValuetv"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:text="#string/tr_focus_balance"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/caloriestv"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:text="#string/tr_calories_def"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
</TableRow>
<!-- title row 2 -->
<TableRow>
<TextView
android:id="#+id/setsLabletv"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="3dp"
android:text="#string/tr_sets"
android:textColor="#ffffff"
android:textSize="8sp"
android:textStyle="bold" />
<TextView
android:id="#+id/repetitionsLabletv"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="3dp"
android:text="#string/tr_reps"
android:textColor="#ffffff"
android:textSize="8sp"
android:textStyle="bold" />
<TextView
android:id="#+id/kilosLabel"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="3dp"
android:text="#string/tr_kilos"
android:textColor="#ffffff"
android:textSize="8sp"
android:textStyle="bold" />
</TableRow>
<!-- data row 2 -->
<TableRow>
<TextView
android:id="#+id/setsValuetv"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:text="#string/tr_sets_def"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/repetitionsValuetv"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:text="#string/tr_reps_def"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/kilostv"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_marginBottom="3dp"
android:layout_marginTop="3dp"
android:text="#string/tr_kilos_def"
android:textColor="#000000"
android:textSize="24sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>

Related

col and row spans in android table layout android

I want to make following layout in android but unable to make because i new to table layout and tried a lot to fix column spans and row spans.
This is what i had tried last, but the problem is the heading in first column, i want a row span of 2 but unable to do that so i put another blank row there.
<LinearLayout
android:id="#+id/fillable_area"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TableLayout
android:id="#+id/fixed_column_table"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_gravity="center_horizontal"
android:padding="2dp"
android:text="Account"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_gravity="center_horizontal"
android:padding="2dp"
android:text=""
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp">
<TableLayout
android:id="#+id/scrollable_table"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_gravity="center_horizontal"
android:layout_span="2"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Opening Balance"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:layout_gravity="center_horizontal"
android:layout_span="2"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Transaction During Period"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:layout_gravity="center_horizontal"
android:layout_span="2"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Closing Balance"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:background="#FFC7C7"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Debit"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:background="#FBFFC7"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Credit"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:background="#FFC7C7"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Debit"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:background="#FBFFC7"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Credit"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:background="#FFC7C7"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Debit"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:background="#FBFFC7"
android:padding="2dp"
android:paddingStart="10dp"
android:text="Credit"
android:textAlignment="textEnd"
android:textColor="#color/black"
android:textSize="12sp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</HorizontalScrollView>
</LinearLayout>
Data in all rows are dynamic except headings.
Please help me.
Thanks

Responsive Table layout for different size screen android

When I am try to develop a simple table layout it's occur a problem. The layout is works fine for big screen. But when I'm use that in small phone then the problem create. The full rows aren't visible.
Can anyone help me out? I just want to make a simple table layout like that:
here what I made xml layout
<TableLayout
android:layout_below="#+id/jonosonkha"
android:layout_width="match_parent"
android:layout_height="250dp"
android:stretchColumns="5">
<TableRow>
<TextView
android:textColor="#000"
android:background="#ffea00"
android:textSize="20sp"
android:text="পরিবার"
android:paddingLeft="5dp" />
<TextView
android:background="#000"
android:textColor="#fff"
android:textSize="20sp"
android:text="পুরুষ"
android:gravity="left"
android:paddingLeft="5dp"/>
<TextView
android:background="#ffea00"
android:textSize="20sp"
android:text="মহিলা"
android:textColor="#000"
android:gravity="center"
android:paddingLeft="5dp" />
<TextView
android:background="#000"
android:textSize="20sp"
android:text="গড় সদস্য"
android:gravity="left"
android:textColor="#fff"
android:paddingLeft="5dp" />
<TextView
android:background="#ffea00"
android:textColor="#000"
android:textSize="20sp"
android:text="ঘনত্ব/কি.মি"
android:gravity="left"
android:paddingLeft="5dp" />
</TableRow>
<TableRow
android:layout_marginTop="2dp"
>
<TextView
android:textColor="#000"
android:background="#ffea00"
android:textSize="16sp"
android:text="৮৯৮৬৩"
android:paddingLeft="5dp" />
<TextView
android:background="#000"
android:textColor="#fff"
android:textSize="16sp"
android:text="২০৫০৭৫"
android:gravity="center"
android:paddingLeft="5dp"/>
<TextView
android:background="#ffea00"
android:textSize="16sp"
android:text="২০৯১১৩"
android:textColor="#000"
android:gravity="center"
android:paddingLeft="5dp" />
<TextView
android:background="#000"
android:textSize="16sp"
android:text="৪.৫৪"
android:gravity="center"
android:textColor="#fff"
android:paddingLeft="5dp" />
<TextView
android:background="#ffea00"
android:textColor="#000"
android:textSize="16sp"
android:text="২১৩৮"
android:gravity="left"
android:paddingLeft="5dp" />
</TableRow>
</TableLayout>
It's works fine for big screen but the problem is some of rows are covered by the small screen. Any solution please.
You want to divide five TextView .
You can add android:layout_width="0dp" 、android:layout_height="match_parent" and android:layout_weight="1" in your TextView .
You can try this .
<TableLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_below="#+id/jonosonkha"
android:stretchColumns="5">
<TableRow>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffea00"
android:paddingLeft="5dp"
android:text="পরিবার"
android:textColor="#000"
android:textSize="20sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000"
android:gravity="left"
android:paddingLeft="5dp"
android:text="পুরুষ"
android:textColor="#fff"
android:textSize="20sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffea00"
android:gravity="center"
android:paddingLeft="5dp"
android:text="মহিলা"
android:textColor="#000"
android:textSize="20sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000"
android:gravity="left"
android:paddingLeft="5dp"
android:text="গড় সদস্য"
android:textColor="#fff"
android:textSize="20sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffea00"
android:gravity="left"
android:paddingLeft="5dp"
android:text="ঘনত্ব/কি.মি"
android:textColor="#000"
android:textSize="20sp"/>
</TableRow>
<TableRow
android:layout_marginTop="2dp">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffea00"
android:paddingLeft="5dp"
android:text="৮৯৮৬৩"
android:textColor="#000"
android:textSize="16sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000"
android:gravity="center"
android:paddingLeft="5dp"
android:text="২০৫০৭৫"
android:textColor="#fff"
android:textSize="16sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffea00"
android:gravity="center"
android:paddingLeft="5dp"
android:text="২০৯১১৩"
android:textColor="#000"
android:textSize="16sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#000"
android:gravity="center"
android:paddingLeft="5dp"
android:text="৪.৫৪"
android:textColor="#fff"
android:textSize="16sp"/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffea00"
android:gravity="left"
android:paddingLeft="5dp"
android:text="২১৩৮"
android:textColor="#000"
android:textSize="16sp"/>
</TableRow>
</TableLayout>
Output
You should define the width attribute of the table rows, like:
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
and the weight attribute of all the Textviews:
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#000"
android:background="#ffea00"
android:textSize="20sp"
android:text="পরিবার"
android:paddingLeft="5dp" />

How to setview in center of a table layout column

I am having a check box with in table layout of five columns and i had placed check boxes in the last column of my table layout but it was not placing at the center of the column can any one tell me how to place check boxes at the center of the column in the table layout in android
This is my xml
<TableLayout
android:id="#+id/table_layout_manual_mode"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
>
<TableRow
android:id="#+id/After_connection_heading_one"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#673AB7" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="CHECK ON J14"
android:textColor="#FFFFFF"
android:textSize="20dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow1_manual"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="0.35"
android:background="#drawable/cell_shape"
android:gravity="center"
android:text="#string/TP_15_Sno"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="1.5"
android:background="#drawable/cell_shape"
android:gravity="center"
android:text="#string/TP_15_Description"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp" />
<TextView
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="1"
android:background="#drawable/cell_shape"
android:gravity="center"
android:text="#string/Test_Point_15"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp" />
<TextView
android:id="#+id/textView4"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="1"
android:background="#drawable/cell_shape"
android:gravity="center"
android:text="#string/TP_15_Range"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp" />
<CheckBox
android:id="#+id/cb_1"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="1"
android:background="#drawable/cell_shape"
android:gravity="center"
/>
</TableRow>
<TableRow
android:id="#+id/tableRow2_manual"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="0.35"
android:background="#drawable/cell_shape"
android:gravity="center"
android:text="#string/TP_16_Sno"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="1.5"
android:background="#drawable/cell_shape"
android:gravity="center"
android:text="#string/TP_16_Description"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="1"
android:background="#drawable/cell_shape"
android:gravity="center"
android:text="#string/Test_Point_16"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="1"
android:background="#drawable/cell_shape"
android:gravity="center"
android:text="#string/TP_16_Range"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp" />
<CheckBox
android:id="#+id/cb_2"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="1"
android:background="#drawable/cell_shape"
android:gravity="center" />
</TableRow>
<TableRow
android:id="#+id/tableRow3_manual"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="0.35"
android:background="#drawable/cell_shape"
android:gravity="center"
android:text="#string/TP_17_Sno"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="1.5"
android:background="#drawable/cell_shape"
android:gravity="center"
android:text="#string/TP_17_Description"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="1"
android:background="#drawable/cell_shape"
android:gravity="center"
android:text="#string/Test_Point_17"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="1"
android:background="#drawable/cell_shape"
android:gravity="center"
android:text="#string/TP_17_Range"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20dp" />
<CheckBox
android:id="#+id/cb_3"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_weight="1"
android:background="#drawable/cell_shape"
android:gravity="center" />
</TableRow>
</TableLayout>

Achieving the same result without paddingLeft property

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dip" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="1dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="20dp"
android:text="Total Pregnancies"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="30dp"
android:text="10"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="160dp"
android:text="Full Term"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="75dp"
android:text="11"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="190dp"
android:text="Premature"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="30dp"
android:text="12"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_below="#+id/linearLayout1"
android:layout_marginTop="35dp"
android:padding="1dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="20dp"
android:text="Multiples"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="85dp"
android:text="16"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="160dp"
android:text="Living"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="95dp"
android:text="17"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_centerVertical="true"
android:padding="1dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="20dp"
android:text="Ab Included"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="70dp"
android:text="13"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="160dp"
android:text="Ab Spontaneous"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="30dp"
android:text="14"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="190dp"
android:text="Ectopics"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="35dp"
android:text="15"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
This is how the screen looks, can anyone tell me how can i achieve this layout. i have come up with the layout, but it seems it does not fit for all screens.
Make the LinearLayout width fill_parent to use the entire width of the screen.
Then for each TextView, set the layout_width to 0dp, and set layout_weight to the proportion of the screen you want that view to have.
In the padding, specify the minimum amount you want between the different cells.
For example, if you want the text to occupy double the space of the numbers, use the following code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dip" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginRight="5dip"
android:padding="1dip" >
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="Total Pregnancies"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="10"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="Full Term"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="11"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="Premature"
android:textColor="#000000" />
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingLeft="5dp"
android:text="12"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
Use TableLayout
Here is an example

Android Portions of TextView Invisible

I have some text views in a table layout. When I click a button in my layout parts of the textviews disappear. I have tried restarting eclipse and the emulator a few times, but nothing has changed. I am completely stumped. Any suggestions for why this may be happening? I have posted a before and after screenshot and my xml code for the table layout
Before Click
After Click
Portions of the XML Code...
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tv_rank"
android:stretchColumns="1" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#acacac"
android:text="Public"
android:textColor="#000000" />
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#acacac"
android:paddingTop="5dp" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1.35"
android:text="Parties Thrown:"
android:textColor="#000000"
android:textSize="12dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/tv_PublicPartyAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" parties"
android:textColor="#000000"
android:textSize="8dp" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.35"
android:text="Average Score:"
android:textColor="#000000"
android:textSize="12dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/tv_PublicAverageScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" points"
android:textColor="#000000"
android:textSize="8dp" />
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#acacac"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1.35"
android:text="Biggest Party:"
android:textColor="#000000"
android:textSize="12dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/tv_PublicBiggestParty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" guests"
android:textColor="#000000"
android:textSize="8dp" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.35"
android:text="Highest Score:"
android:textColor="#000000"
android:textSize="12dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/tv_PublicHighestScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" points"
android:textColor="#000000"
android:textSize="8dp" />
</LinearLayout>
</TableRow>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="5dp" >
</LinearLayout>
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#acacac"
android:text="Private"
android:textColor="#000000" />
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#acacac"
android:paddingTop="5dp" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1.35"
android:text="Parties Thrown:"
android:textColor="#000000"
android:textSize="12dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/tv_PrivatePartyAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" parties"
android:textColor="#000000"
android:textSize="8dp" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.35"
android:text="Average Score:"
android:textColor="#000000"
android:textSize="12dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/tv_PrivateAverageScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" points"
android:textColor="#000000"
android:textSize="8dp" />
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#acacac"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1.35"
android:text="Biggest Party:"
android:textColor="#000000"
android:textSize="12dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/tv_PrivateBiggestParty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" guests"
android:textColor="#000000"
android:textSize="8dp" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.35"
android:text="Highest Score:"
android:textColor="#000000"
android:textSize="12dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/tv_PrivateHighestScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:textColor="#000000"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" guests"
android:textColor="#000000"
android:textSize="8dp" />
</LinearLayout>
</TableRow>
</TableLayout>

Categories

Resources