android design xml layout alignment (how to draw the like that) - android

How to design the following as shown in the picture:
my xml structure is:
<Root>
<other design>
<need to design as in picture>
</Root>
the picture is :
that is the text should appear in left and right alignment.

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="HOUR"
android:textColor="#C0C0C0" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="$1.80"
android:textColor="#6686A8" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="DAY"
android:textColor="#C0C0C0" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="$10.00"
android:textColor="#6686A8" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="WEEK"
android:textColor="#C0C0C0" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="$35.00"
android:textColor="#6686A8" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="MONTH"
android:textColor="#C0C0C0" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="$105.00"
android:textColor="#6686A8" />
</TableRow>
</TableLayout>

You can use TableLayout to achieve that kind of layout.

Related

Layout issue with ScrollView & table

I have a form using ScrollView. There are 2 spinners in the form and in portrait mode one of spinners goes out of the screen but in landscape view the spinner is visible. What setting needs to be changed so that spinner does not go out of the screen? (Comment- The label Select Month in the image should actually be "Select Month & Year" )
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20sp">
<!-- android:layout_width="wrap_content"
android:layout_height="match_parent"
-->
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/back"
android:scrollbars="vertical"
android:textSize="20sp">
<!--Month Combo Box-->
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Month & Year"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<Spinner
android:id="#+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<Spinner
android:id="#+id/spinneryr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#0c0b0b"
android:textSize="20sp" />
</TableRow>
<!--Field1 Combo Box-->
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ERYTHROCYTE"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<EditText
android:id="#+id/ERYTHROCYTE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:inputType="numberDecimal" />
</TableRow>
<!--Field2 Combo Box-->
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/HAEMOGLOBIN"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<EditText
android:id="#+id/HAEMOGLOBIN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:inputType="numberDecimal" />
</TableRow>
<!--Field3 Combo Box-->
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/PCV"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<EditText
android:id="#+id/PCV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:inputType="numberDecimal" />
</TableRow>
<!--Field4 Combo Box-->
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/RDW"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<EditText
android:id="#+id/RDW"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:inputType="numberDecimal" />
</TableRow>
<!--Field5 Combo Box-->
<TableRow
android:id="#+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/MCV"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<EditText
android:id="#+id/MCV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:gravity="center"
android:inputType="numberDecimal" />
</TableRow>
<!--Field6 Combo Box-->
<TableRow
android:id="#+id/tableRow7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/MCH"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<EditText
android:id="#+id/MCH"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:inputType="numberDecimal" />
</TableRow>
<!--Field7 Combo Box-->
<TableRow
android:id="#+id/tableRow8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/MCHC"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<EditText
android:id="#+id/MCHC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:gravity="center"
android:inputType="numberDecimal" />
</TableRow>
<!--Field8 Combo Box-->
<TableRow
android:id="#+id/tableRow9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LEUCOCYTECOUNT"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<EditText
android:id="#+id/LEUCOCYTECOUNT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:gravity="center"
android:inputType="numberDecimal" />
</TableRow>
<!--Field9 Combo Box-->
<TableRow
android:id="#+id/tableRow10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/PLATELETS"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<EditText
android:id="#+id/PLATELETS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:gravity="center"
android:inputType="numberDecimal" />
</TableRow>
<!--Field10 Combo Box-->
<TableRow
android:id="#+id/tableRow11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/NEUTROPHILS"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<EditText
android:id="#+id/NEUTROPHILS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:gravity="center"
android:inputType="numberDecimal" />
</TableRow>
<!--Field11 Combo Box-->
<TableRow
android:id="#+id/tableRow12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/EOSINOPHILS"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<EditText
android:id="#+id/EOSINOPHILS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:gravity="center"
android:inputType="numberDecimal" />
</TableRow>
<!--Field12 Combo Box-->
<TableRow
android:id="#+id/tableRow13"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20sp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/LYMPHOCYTES"
android:textColor="#0c0b0b"
android:textSize="20sp" />
<EditText
android:id="#+id/LYMPHOCYTES"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/back"
android:gravity="center"
android:inputType="numberDecimal" />
</TableRow>
<!-- Button :Start here-->
<TableRow
android:id="#+id/tableRow14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20sp">
<Button
android:id="#+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/add" />
<Button
android:id="#+id/btnViewAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/view_all" />
</TableRow>
<!--<Button
android:id="#+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/delete" />
<Button
android:id="#+id/btnShowInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/show_info" />
</TableRow>-->
<!-- <TableRow
android:id="#+id/tableRow15"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20sp">
<Button
android:id="#+id/btnModify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/modify" />
<Button
android:id="#+id/btnView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/view" />
<Button
android:id="#+id/btnShowInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/show_info" >
</TableRow-->
<TextView
android:id="#+id/tvValues"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="20sp" />
</TableLayout>
</ScrollView>
What setting needs to be changed so that spinner does not go out of the screen?
None. There's no settings for that - it's basically how you made your layout and it simply does not fit. You can consider having separate layout file for each orientation so you'd i.e. put spinners vertically for portrait layout -> just create layout-land in your res/ and copy current layout there. Then edit the one in layout to make it better fit the screen. That's it.
I am posting answer to my question. I managed to fix the issue by doing the following changes to ScrollView. After the change the TextView & both spinners are now visible on the same row and well aligned.
Code changes to ScrollView -
1) Updating android:layout_width="fill_parent"
2) Updating android:layout_height="fill_parent"
3) Adding android:fillViewport="true"
Code changes to TableLayout
1) Added android:layout_centerInParent="true"
2) Added android:gravity="center"
Solution suggested by #Marcin is another way (probably a more versatile solution) to solve the issue but since the above solution worked I did not try it.

Android: Textview out of boundary

I have been trying to make this Layout which contains a Textview in a TableLayout. The textview however doesn't fit inside the layout. It goes out of the boundary. Changing the width to fill_parent or wrap_content doesn't seem to fix it.
Please see this screenshot
The following is the xml code:
<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:orientation="vertical"
tools:context=".ReportDetailActivity" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="#drawable/camera_icon" />
<TextView
android:id="#+id/textViewCategory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="Pothole"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comment : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textViewComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textViewLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaadsk jfshdfhsdkh fdsfdshfkdshfk hsdkhfk sdhkfhsd;kfhs"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textViewDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
</TableLayout>
Try add the layout_weight;
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location : "
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textViewLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="aaaaaadsk jfshdfhsdkh fdsfdshfkdshfk hsdkhfk sdhkfhsd;kfhs"
android:textAppearance="?android:attr/textAppearanceLarge" />
Try giving fix width to the textview. This will prevent from text going off the screen:
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textViewLocation"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="aaaaaadsk jfshdfhsdkh fdsfdshfkdshfk hsdkhfk sdhkfhsd;kfhs"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
Use 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:orientation="vertical"
tools:context=".ReportDetailActivity" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside"
android:src="#drawable/camera_icon" />
<TextView
android:id="#+id/textViewCategory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:text="Pothole"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comment : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textViewComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textViewLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="aaaaaadsk jfshdfhsdkh fdsfdshfkdshfk hsdkhfk sdhkfhsd;kfhs"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date : "
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textViewDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
</TableLayout>
</LinearLayout>
try to set fix layout_width to your textview and set maxlines or minlines attribute if needed.

Android: Image button is not alligned to right

I want my image button to be placed on the rt side bottom of the scree. but it is not getting visible.Please see the code.
<RelativeLayout 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"
tools:context=".MainActivity" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date of Birth:" />
<Button
android:id="#+id/dateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:text="Select date" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Manual labour" />
<EditText
android:id="#+id/ed1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:inputType="number" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender :" />
<RadioGroup
android:id="#+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Male" />
<RadioButton
android:id="#+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Occupation" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/occuaption_arrays"
android:prompt="#string/occupation_prompt" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Monthly Income" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/income_arrays"
android:prompt="#string/income_prompt" />
</TableRow>
</TableLayout>
<ImageButton
android:id="#+id/next"
android:layout_height="50dp"
android:layout_width="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:contentDescription="dfg"
android:src="#drawable/next"
android:visibility="visible"/>
I have tried using RelativeLayout as parent and add attribute android:layout_alignParentRight="true" and android:layout_alignParentBottom="true"
My image is very large.Is that can be a problem?
You have setted match-parent to width and height of TableLayout. So TableLayout overlaps ImageButton
use below code...
android:layout_width="match_parent"
android:layout_height="wrap-content"

Android TableLayout wrap content

I have a LinearLayout with TableLayout and LinearLayout inside. TableLayout is made up of 5 TableRows. Each TableRow is made up of two View objects.
Firt column has two TextViews, my problem is that the text of TexView is wrapped:
The word SomeValue is wrapped, the letter e is a in new line, I'd like all in just one row, in this case and in general case, wath's the way pattern?
For example:
<?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:gravity="center"
android:orientation="vertical"
android:padding="#dimen/padding_small"
android:id="#+id/layout1">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal|top"
android:stretchColumns="0,true"
android:shrinkColumns="*,true">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Value1"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Spinner
android:id="#+id/spinnerPrefix"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
**<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SomeValue"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/valueU"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" >
<requestFocus />
</EditText>
</TableRow>**
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Mytext"
android:textAppearance="?android:attr/textAppearanceSmall"
/>
<EditText
android:id="#+id/valueN"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AnyValue"
android:textAppearance="?android:attr/textAppearanceSmall" />
<DatePicker
android:id="#+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Some"
android:textAppearance="?android:attr/textAppearanceSmall" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<RadioButton
android:id="#+id/radioM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="M" />
<RadioButton
android:id="#+id/radioF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="F" />
</RadioGroup>
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="#dimen/padding_small" >
<Button
android:id="#+id/buttonRegistrazione"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send Data" />
</LinearLayout>
</LinearLayout>
For each textview you could add
android:singleLine = "true"
That will make it a single line. If the text is too big then you could use ellipsize
android:ellipsize
to control how you want the text to appear

Android: when wrap_content doesn't just wrap its content?

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>

Categories

Resources