I am writing code for an activity that has a table that initially contains 2 rows(see screenshot). I would like the text in those 2 rows to be in the center(not the TextView).
However, setting android:gravity = "center" or android:gravity = "center_horizontal" does not affect the text at all.
What am I missing?
Screenshot
activity_game.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:background="#android:color/white"
android:orientation="horizontal"
android:padding="16dp"
tools:context=".MainActivity">
<TableLayout
android:id="#+id/tl1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TableRow
android:id="#+id/tr_header_p1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/table_row_bg"
android:padding="5dp">
<TextView
android:id="#+id/player1_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Player 1"
android:textColor="#000000"
android:textSize="24sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/table_row_bg"
android:padding="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/table_cell_bg"
android:gravity="center"
android:text="Guess"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/table_cell_bg"
android:gravity="center"
android:text="Bulls"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Cows"
android:textColor="#000000"
android:textSize="16sp" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/tl2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TableRow
android:id="#+id/tr_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/table_row_bg"
android:padding="5dp">
<TextView
android:id="#+id/player2_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Player 2"
android:textColor="#000000"
android:textSize="24sp" />
</TableRow>
<TableRow
android:id="#+id/tr_header2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/table_row_bg"
android:padding="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/table_cell_bg"
android:gravity="center"
android:text="Guess"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/table_cell_bg"
android:gravity="center"
android:text="Bulls"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Cows"
android:textColor="#000000"
android:textSize="16sp" />
</TableRow>
</TableLayout>
Try this should work,
add android:gravity="center" to your #+id/tr_header_p1 and #+id/tr_header
like,
<TableRow
android:id="#+id/tr_header_p1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="5dp">
and
<TableRow
android:id="#+id/tr_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:padding="5dp">
this might helps you
EDIT 1
or you need to mention the android:layout_weight="1" to your TextView. like
<TextView
android:id="#+id/player2_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="Player 2"
android:textColor="#000000"
android:textSize="24sp" />
Try this:
<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:background="#android:color/white"
android:orientation="horizontal"
android:padding="16dp"
tools:context=".MainActivity">
<TableLayout
android:id="#+id/tl1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TableRow
android:id="#+id/tr_header_p1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#drawable/table_row_bg"
android:padding="5dp">
<TextView
android:id="#+id/player1_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Player 1"
android:textColor="#000000"
android:textSize="24sp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/table_row_bg"
android:padding="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/table_cell_bg"
android:gravity="center"
android:text="Guess"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/table_cell_bg"
android:gravity="center"
android:text="Bulls"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Cows"
android:textColor="#000000"
android:textSize="16sp" />
</TableRow>
</TableLayout>
<TableLayout
android:id="#+id/tl2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TableRow
android:id="#+id/tr_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="#drawable/table_row_bg"
android:padding="5dp">
<TextView
android:id="#+id/player2_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Player 2"
android:textColor="#000000"
android:textSize="24sp" />
</TableRow>
<TableRow
android:id="#+id/tr_header2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/table_row_bg"
android:padding="5dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/table_cell_bg"
android:gravity="center"
android:text="Guess"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/table_cell_bg"
android:gravity="center"
android:text="Bulls"
android:textColor="#000000"
android:textSize="16sp" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Cows"
android:textColor="#000000"
android:textSize="16sp" />
</TableRow>
</TableLayout>
</LinearLayout>
You can try setting layout_width to wrap_content and then set layout_gravity to center.
That align the entire TextView and not the text inside it
What if you used android:layout_gravity from your TextView which is gonna affect the position of the element according its parent? There's a thread explaining the difference between both below
Gravity and layout_gravity on Android
<TableRow
android:id="#+id/tr_header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/table_row_bg"
android:gravity="center_horizontal"
android:padding="5dp">
<TextView
android:id="#+id/player2_name"
android:layout_width="match_parent"
android:gravity="center"
android:text="Player 2"
android:textColor="#000000"
android:textSize="24sp" />
</TableRow>
This is working for me
try for the TableRow parent of TextView
android:gravity="CENTER_HORIZONTAL"
the default layout of a table it's applied to children nodes, as described in documentation here
Related
I am trying to add a table inside a linear layout. Inside my linear layout there is textview, spinner. When I try to add a table layout it doesn't align correctly. Below is my code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/cardLayout"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product"
android:gravity="center"
android:textStyle="bold"
android:textSize="18sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:layout_margin="10sp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:orientation="vertical">
<Spinner
android:id="#+id/product_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
</LinearLayout>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
>
<TableRow android:background="#0079D6" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Product Name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sale" />
</TableRow>
<TableRow android:background="#DAE8FC" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
Output
Expected Output
I must be missing something that I don't know. How can I align them equally just like in the above image
Any help would be highly appreciated.
Try using below code:
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Product"
android:gravity="center"
android:textStyle="bold"
android:textSize="18sp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
<Spinner
android:id="#+id/product_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
/>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_gravity="center"
>
<TableRow android:background="#0079D6" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Product Name" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sale" />
</TableRow>
<TableRow android:background="#DAE8FC" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="" />
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
i am new in android studio.
currently i making listview, i want to make layout like this picture :
this is my code now
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="3">
<TableLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Type"
android:textSize="18dp"
android:fontFamily="sans-serif"
android:textColor="#color/black"
android:id="#+id/tvTipeRequest"
android:width="130dp" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Date"
android:fontFamily="sans-serif"
android:id="#+id/tvTanggalRequest"
android:textSize="15dp"
android:width="130dp" />
</TableRow>
</TableLayout>
<TextView
android:layout_width="1dp"
android:layout_weight="1"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:text="Status"
android:textSize="15dp"
android:gravity="end"
android:paddingTop="10dp"
android:fontFamily="sans-serif"
android:layout_marginTop="15dp"
android:id="#+id/tvStatus"
android:layout_column="38" />
</TableRow>
</TableLayout>
i realize that tablerow cant do the rowspan, so it didnt work out.
is there any simple way to do that?
Use this hierarchy:
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:weightSum="1"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.2"
android:orientation="vertical"
android:layout_height="wrap_content">
<!--ImageView here-->
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="0.8"
android:orientation="vertical"
android:layout_height="wrap_content">
<!--All textViews here-->
</LinearLayout>
</LinearLayout>
You can have a single relative layout as your view container. That would be more efficient.
Read.
Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:src="#drawable/circle" />
<TextView
android:id="#+id/text_view_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/image_view"
android:text="text_1"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/text_view_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text_view_1"
android:layout_toRightOf="#+id/image_view"
android:text="text_2"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/text_view_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text_view_2"
android:layout_toRightOf="#+id/image_view"
android:text="text_3"
android:textColor="#android:color/black" />
<TextView
android:id="#+id/text_view_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text_view_3"
android:layout_toRightOf="#+id/image_view"
android:text="text_4"
android:textColor="#android:color/black" />
</RelativeLayout>
Output:
I have problem with textviews alignment. I want to align two textviews for the listview item to left and to right. In the Android Studio editor it's ok but when I'm deploying application to the device it's not right aligned. I don't know what is the problem. Below is my layout:
Found the problem. Issue actually was with the listview by mistake I set Listview's layout_width="wrap_content" but should be match_parent. As the mentioned layout is the list's item layout. Thanks everyone.
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="#dimen/activity_horizontal_margin"
android:orientation="vertical">
<TextView
android:id="#+id/tv_order_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:id="#+id/tv_order_category_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
<TextView
android:id="#+id/tv_order_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="35sp"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/order_tin_ein"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_order_tin_ein"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="1"
android:text="Test"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:text="#string/order_address"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_order_address"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/order_email"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_order_email"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/order_phone"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_order_phone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/order_mobile"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_order_mobile"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/order_fax"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_order_fax"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/order_created_date"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_order_created_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/order_start_working_date"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_order_start_working_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/order_end_date"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_order_end_date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/order_cost"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_order_cost"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/order_vat"
android:gravity="left"
android:layout_weight="1"
android:textStyle="bold"/>
<TextView
android:id="#+id/tv_order_vat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"/>
</TableRow>
</TableLayout>
I think your code it's fine, and this one will improve for your code better.
Just using gravity:right if you wanna put it on the right.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="asd"
android:gravity="left"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_order_tin_ein"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Test" />
</LinearLayout>
Try this :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Text1"
android:layout_weight="1"/>
<TextView
android:text="Text2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
I have an issue where I am showing a fragment in a scrollview,but the thing is that the scrillview always shows extra space(or I think complete fragment page) while the data is only half page. How can I make scrollview not showing the whole fragment page and only the text part.I though of making the parent LinareLayout wrap in fragment activity but doesn't work for me.
The activity xml where inside a scrolview a LinearLayout is put and later I replace it with a fragment
<?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:background="#ffffffff"
android:orientation="vertical"
android:weightSum="10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1.1"
android:background="#FF52caf7"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="15dp"
android:clickable="true"
android:onClick="backtoschedule"
android:src="#drawable/back" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal"
android:text="Schedule Order"
android:textColor="#FFFFFFFF"
android:textSize="#dimen/txtm" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="7.9"
android:background="#drawable/pbackground"
android:orientation="vertical"
android:weightSum="10.05">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5.975"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/defaultsofragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.025"
android:background="#ffd1d1d1" />
///////////////////////////////////////////////////////////////////////////
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal"
android:weightSum="10">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="6"
android:orientation="vertical"
android:weightSum="10">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="6"
android:gravity="left"
android:paddingLeft="10dp"
android:text="Instruction"
android:textColor="#ff000000"
android:textSize="#dimen/txtss" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="left"
android:paddingLeft="10dp"
android:text="You agree with terms and conditions"
android:textColor="#ff000000"
android:textSize="#dimen/txts2" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:orientation="vertical"
android:weightSum="10">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center|left"
android:text="Use Coupon"
android:textColor="#ff000000"
android:textSize="#dimen/txtss" />
<EditText
android:id="#+id/couponcode"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="20dp"
android:layout_marginRight="20dp"
android:layout_weight="6"
android:background="#drawable/edittextstyle"
android:gravity="center"
android:hint="coupon code"
android:textColor="#ff000000"
android:textColorHint="#FFABABAB"
android:textCursorDrawable="#null"
android:textSize="#dimen/txtss" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.025"
android:background="#ffd1d1d1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#drawable/img"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:id="#+id/button"
style="#android:style/TextAppearance.Large"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="#ff57caf2"
android:onClick="orderconfirm"
android:text="Confirm Order"
android:textColor="#fff0f0f0"
android:textSize="#dimen/txtss" />
</LinearLayout>
</LinearLayout>
////////////////////////////////////////
The fragment activity 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="wrap_content"
android:background="#drawable/pbackground"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*">
<TableRow
android:layout_weight="1"
android:gravity="left">
<TextView
android:layout_column="1"
android:padding="3dip"
android:text="ORDER DETAILS"
android:textAllCaps="true"
android:textColor="#000"
android:textSize="#dimen/txtss" />
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="left"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_column="1"
android:layout_weight="0.5"
android:padding="3dip"
android:text="Delivery Type"
android:textColor="#ff000000"
android:textSize="#dimen/txts"
android:textStyle="bold" />
<TextView
android:id="#+id/dtype"
android:layout_width="0dp"
android:layout_column="1"
android:layout_weight="0.5"
android:padding="3dip"
android:text="Loading..."
android:textColor="#ff000000"
android:textSize="#dimen/txts" />
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="left"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_column="1"
android:layout_weight="0.5"
android:padding="3dip"
android:text="Schedule Pickup"
android:textColor="#ff000000"
android:textSize="#dimen/txts"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="left"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_column="1"
android:layout_weight="0.5"
android:padding="3dip"
android:text="Date"
android:textColor="#FF000000"
android:textSize="#dimen/txts" />
<TextView
android:id="#+id/spdate"
android:layout_width="0dp"
android:layout_column="1"
android:layout_weight="0.5"
android:padding="3dip"
android:text="Loading..."
android:textColor="#FF000000"
android:textSize="#dimen/txts" />
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="left"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_column="1"
android:layout_weight="0.5"
android:padding="3dip"
android:text="Time"
android:textColor="#FF000000"
android:textSize="#dimen/txts" />
<TextView
android:id="#+id/sptime"
android:layout_width="0dp"
android:layout_column="1"
android:layout_weight="0.5"
android:padding="3dip"
android:text="Loading..."
android:textColor="#FF000000"
android:textSize="#dimen/txts" />
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="left"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_column="1"
android:layout_weight="0.5"
android:padding="3dip"
android:text="Schedule DropOff"
android:textColor="#ff000000"
android:textSize="#dimen/txts"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="left"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_column="1"
android:layout_weight="0.5"
android:padding="3dip"
android:text="Date"
android:textColor="#FF000000"
android:textSize="#dimen/txts" />
<TextView
android:id="#+id/sddate"
android:layout_width="0dp"
android:layout_column="1"
android:layout_weight="0.5"
android:padding="3dip"
android:text="Loading..."
android:textColor="#FF000000"
android:textSize="#dimen/txts" />
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="left"
android:weightSum="1">
<TextView
android:layout_width="0dp"
android:layout_column="1"
android:layout_weight="0.5"
android:padding="3dip"
android:text="Time"
android:textColor="#FF000000"
android:textSize="#dimen/txts" />
<TextView
android:id="#+id/sdtime"
android:layout_width="0dp"
android:layout_column="1"
android:layout_weight="0.5"
android:padding="3dip"
android:text="Loading..."
android:textColor="#FF000000"
android:textSize="#dimen/txts" />
</TableRow>
<View
android:layout_height="1dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:gravity="center" />
<TableRow
android:layout_weight="1"
android:gravity="left">
<TextView
android:layout_column="1"
android:padding="3dip"
android:text="Address"
android:textAllCaps="true"
android:textColor="#000"
android:textSize="#dimen/txtss" />
</TableRow>
<TableRow
android:layout_weight="1"
android:gravity="left">
<TextView
android:id="#+id/caddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:inputType="textMultiLine"
android:padding="3dip"
android:scrollbars="vertical"
android:text="Shanti Niketanjnkwejrkjwoperjposdasdasdasdasdasdasdwejprjwpoe,Lucknow,22-44-33"
android:textColor="#000"
android:textSize="#dimen/txts" />
</TableRow>
</TableLayout>
</LinearLayout>
use this attribute inside Scrollview..
android:fillViewport="true"
I have a following xml layout in my project (incidentally, if you notice something else that is also seemingly wrong/not so good yet, I'd appreciate you let me know about it!) and my problem is the attribute "wrap_contents" doesn't work at the last TextView ("EEE", txt4). Is there any regulation I overlook?
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TableLayout
android:id="#+id/Table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="AAA"
android:textColor="#color/white" />
<Spinner
android:id="#+id/spn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="#array/array1" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/edt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="BBB"
android:textColor="#color/white" />
<Spinner
android:id="#+id/spn2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:entries="#array/Tounyuhou" />
<EditText
android:id="#+id/edt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:inputType="numberSigned"/>
<TextView
android:id="#+id/txt2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="CCC" android:textColor="#color/white"
android:gravity="center_vertical|center_horizontal"
android:textSize="18sp"/>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="DDD"
android:textColor="#color/white" />
<EditText
android:id="#+id/edt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|center_vertical">
</EditText>
<TextView
android:id="#+id/txt4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="EEE"
android:textColor="#color/white"
android:gravity="center_vertical|center_horizontal"
android:textSize="20sp"/>
</TableRow>
</TableLayout>
</merge>
here you define all the rows in same layout , but with different number of views, like row1 contain 2 , row2 contain 4 then row3 contain 3 views,
so it gives problem,
so my suggetion take different tablelayout for third row.
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TableLayout
android:id="#+id/mainTable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TableRow
android:id="#+id/mainTable_tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TableLayout
android:id="#+id/Table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="AAA"
android:textColor="#color/white" />
<Spinner
android:id="#+id/spn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="#array/array1" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/edt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="BBB"
android:textColor="#color/white" />
<Spinner
android:id="#+id/spn2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:entries="#array/Tounyuhou" />
<EditText
android:id="#+id/edt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:inputType="numberSigned"/>
<TextView
android:id="#+id/txt2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="CCC" android:textColor="#color/white"
android:gravity="center_vertical|center_horizontal"
android:textSize="18sp"/>
</TableRow>
</TableLayout>
</TableRow>
<TableRow
android:id="#+id/mainTable_tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<TableLayout
android:id="#+id/Table2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TableRow
android:id="#+id/table2_tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:text="DDD"
android:textColor="#color/white" />
<EditText
android:id="#+id/edt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right|center_vertical">
</EditText>
<TextView
android:id="#+id/txt4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="EEE"
android:textColor="#color/white"
android:gravity="center_vertical|center_horizontal"
android:textSize="20sp"/>
</TableRow>
</TableLayout>
</TableRow>
</TableLayout>
</merge>