I am trying to align in the center 2 buttons in a table row, no matter the screen resolution, so i am trying to avoid using specified margins.
This is my code, it works only with declared margins, and i am using gravity and layout gravity...nothing worked for me. They did not align in the center.
Does anyone have an idea? Thanks anyway.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
android:id="#+id/TableLayout01"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100px"
android:stretchColumns="1" >
<TableRow
android:id="#+id/TableRow01"
android:layout_gravity="center"
android:paddingLeft="50dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/image1Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:drawablePadding="-5sp"
android:drawableTop="#drawable/image1"
android:gravity="center"
android:src="#drawable/image1"
android:text="#string/image1text"
android:textColor="#color/darkgrey" />
<Button
android:id="#+id/image2Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:drawablePadding="-5sp"
android:drawableTop="#drawable/image2"
android:gravity="center"
android:src="#drawable/image2"
android:text="#string/image2text"
android:textColor="#color/darkgrey" />
</TableRow>
<TableRow
android:id="#+id/TableRow02"
android:paddingLeft="50dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/image3Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:drawablePadding="-5sp"
android:drawableTop="#drawable/image3"
android:gravity="center"
android:src="#drawable/image3"
android:text="#string/image3text"
android:textColor="#color/darkgrey" />
<Button
android:id="#+id/image4Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:drawablePadding="-5sp"
android:drawableTop="#drawable/image4"
android:gravity="center"
android:src="#drawable/image4"
android:text="#string/image4text"
android:textColor="#color/darkgrey" />
</TableRow>
</TableLayout>
</RelativeLayout>
</ScrollView>
Put your buttons in a couple of LinearLayouts instead of a TableRow.
<TableLayout
...
>
<LinearLayout
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
>
<Button
android:id="#+id/image1Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:drawablePadding="-5sp"
android:drawableTop="#drawable/image1"
android:src="#drawable/image1"
android:text="#string/image1text"
android:textColor="#color/darkgrey" />
<Button
android:id="#+id/image2Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:drawablePadding="-5sp"
android:drawableTop="#drawable/image2"
android:src="#drawable/image2"
android:text="#string/image2text"
android:textColor="#color/darkgrey" />
</LinearLayout>
</LinearLayout>
...
</TableLayout>
The outer LinearLayout will be stretched to the width of the TableLayout and have its height set to wrap_content by TableLayout. The inner LinearLayout will be centered horizontally in the outer LinearLayout because the latter is vertically oriented.
<LinearLayout android:id="#+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:background="#drawable/wood">
<ScrollView android:id="#+id/ScrollView01" android:layout_width="fill_parent" android:layout_height="fill_parent">
<AbsoluteLayout android:id="#+id/absoluteLayout1" android:layout_width="match_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:paddingLeft="10dp" android:paddingRight="10dp">
<TableLayout android:id="#+id/tableLayout0" android:background="#drawable/my_border" android:layout_width="fill_parent" android:layout_y="150dp" android:layout_height="match_parent">
<TableRow android:layout_height="wrap_content" android:id="#+id/tableRow1" android:layout_width="wrap_content">
<TextView android:id="#+id/EmailID" android:text="EmailID" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#drawable/my_border2" android:textStyle="bold" android:layout_weight="1"></TextView>
<EditText android:id="#+id/txtEmailID" android:layout_width="150dp" android:background="#drawable/my_border1" android:layout_height="wrap_content" android:layout_weight="1">
<requestFocus></requestFocus>
</EditText>
</TableRow>
<TableRow android:layout_height="wrap_content" android:id="#+id/tableRow6" android:layout_width="wrap_content" android:paddingTop="20dp">
<Button android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Cancel"></Button>
<Button android:id="#+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Login"></Button>
</TableRow>
</TableLayout>
</AbsoluteLayout>
</ScrollView>
</LinearLayout>
Related
In this code I need align the buttons a Textview to the left, I try everythnin , with relative layout, gravity etcc....
I dont now why this align still togehter to the center in horizontal line, I need to the left side!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/dark_background"
android:orientation="vertical"
android:gravity="left" >
<ScrollView android:id="#+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:gravity="left"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="6dip"
>
<TextView
android:id="#+id/help_page_intro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/help_page_intro"
android:padding="2dip"
android:layout_weight="1"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="4dip"
android:layout_gravity="left"
>
<Button android:id="#+id/help_button1"
android:layout_weight="1"
android:layout_width="180dip"
android:layout_height="wrap_content"
style="#style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="#string/help_title_section1"
android:drawableTop="#drawable/help_image1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/help_text_section1"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<Button android:id="#+id/help_button2"
android:layout_weight="1"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:gravity="left"
style="#style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="#string/help_title_section2"
android:drawableTop="#drawable/help_image2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/help_text_section2"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentLeft="true">
<Button android:id="#+id/help_button3"
android:layout_weight="1"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
style="#style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="#string/help_title_section3"
android:drawableTop="#drawable/help_image3"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/help_text_section3"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left" >
<Button android:id="#+id/help_button4"
android:layout_weight="1"
android:layout_alignParentLeft="true"
android:layout_width="180dip"
android:layout_height="wrap_content"
android:gravity="left"
style="#style/HelpButton.Dark"
android:onClick="onClickHelp"
android:text="#string/help_title_section4"
android:drawableTop="#drawable/help_image4"/>
<TextView
android:layout_width="wrap_content"
android:gravity="left"
android:layout_height="wrap_content"
android:text="#string/help_text_section4"
android:padding="8dip"
android:layout_weight="1"
/>
</LinearLayout>
Sorry, not fully understanding. Did you want them lined up vertically? Then that would just be setting orientation to vertical in the linear layout. I looked at what this xml does right now. It appears to be button which is half the screen and textview with is the other half. Could you explain a little more what you want to see?
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="4dip"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<Button android:id="#+id/help_button1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:onClick="onClickHelp"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView
android:id="#+id/help_page_intro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:textColor="#color/black"
android:padding="2dip"
android:layout_weight="1"
/>
<View
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
I still didn`t a solution how to do that in XML. I want to center a textview over a imagebutton that are on a tablerow.
This is how should be:
My code:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:layout_below="#+id/button"
android:layout_marginTop="85dp">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="30dip" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:id="#+id/imageButton5"
android:src="#drawable/options_460"
android:layout_span="3"
android:layout_gravity="left"/>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:padding="0dip" >
<ImageButton
android:layout_height="wrap_content"
android:background="#null"
android:id="#+id/a"
android:src="#drawable/buttonsh"
android:layout_weight="1"
android:onClick="rasp"
android:tag="a"
android:layout_gravity="right"
/>
<ImageButton
android:layout_height="wrap_content"
android:background="#null"
android:id="#+id/b"
android:src="#drawable/buttonsh"
android:layout_weight="1"
android:onClick="rasp"
android:tag="b"
android:layout_gravity="left"/>
</TableRow>
............................................
</TableLayout>
Is there any way to do that? Any suggestion would be welcomed.
Thank you for reading.
First thing is that there is no need to take the table view, we have the easy alternative for it, you should try like below... here you have to just set a background 9.pach in your button and take appropriate id for the related component and you will bit your task. good luck
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/darker_gray"
android:gravity="center"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:text="Middle center text" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="2" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="left upper" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="right upper" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="2" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="left bottom" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="right bottom" />
</LinearLayout>
</LinearLayout>
I need to display checkbox. All the check-boxes should align themselves at the extreme right of the screen.However, if I change the orientation of my screen the check-box comes at the middle of the screen.Please help me to solve the issue.Thanks in advance
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
>
<LinearLayout android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:orientation="vertical"
android:layout_margin="10dp">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sf_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="50dp"
android:background="#drawable/test"
>
<View android:id="#+id/Divider_7"
android:layout_height="0.5dp"
android:layout_width="fill_parent"
android:background="#808080"
android:layout_marginBottom="5dp"
/>
<TableRow
android:id="#+id/tbr6"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="2dip"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
>
<TextView
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:textColor="#3399CC"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Pages For Website (existing pages plus new ones you need)-Contact Us"
></TextView>
</TableRow>
<View android:id="#+id/Divider_2"
android:layout_height="1.5dp"
android:layout_width="fill_parent"
android:background="#C0C0C0"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
/>
<TableRow
android:id="#+id/tbr9"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="2dip"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
>
<TextView
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:textColor="#ffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Feedback"
></TextView>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/feedback_id"
android:layout_gravity="right"
></CheckBox>
</TableRow>
<TableRow
android:id="#+id/tbr9"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="2dip"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
>
<TextView
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:textColor="#ffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Tech Support"
></TextView>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/techsupport_id"
android:layout_gravity="right"
></CheckBox>
</TableRow>
<TableRow
android:id="#+id/tbr9"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_margin="2dip"
android:layout_marginTop="3dp"
android:layout_marginBottom="3dp"
>
<TextView
android:textStyle="bold"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:textColor="#ffffff"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Quote Form"
></TextView>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/quoteform_id"
android:layout_gravity="right"
></CheckBox>
</TableRow>
</TableLayout>
</RelativeLayout>
</ScrollView>
</LinearLayout>
try the following
android:layout_gravity="right"
android:gravity="right"
android:layout_gravity is not relevant in a LinearLayout. It is meant for a FrameLayout. It means "what should be my gravity in relation to my (FrameLayout) father". android:gravity on the other hand means "what is the gravity inside me" and it applies to different views differently (like in a TextView it will align the text according to the gravity).
I think you could probably throw out half of the layouts you are using to display views (it's kind of confusing and hard to read) by simplifying your layout scheme and use just using a RelativeLayout for alignment issues (align to parent or to other views) and LinearLayout for grouping vertical and horizontal groups.
use tablelayout an then use tablerowlayout. and put your checkboxes.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#ffffffff"
android:text="ARE YOU CLASS 2B?" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="50dp"
android:layout_height="50dp" >
<RadioGroup
android:id="#+id/radioGroup" android:textColor="#000000"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<RadioButton
android:id="#+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Yes" />
<RadioButton
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No" />
</RadioGroup>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/jimmy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jimmy" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/diana"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Diana" />
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/dina"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dina" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/jack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jack" />
</TableRow>
<TextView
android:id="#+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TableRow
android:id="#+id/tableRow7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
</TableLayout>
</LinearLayout>
It's example hehe
I am trying to build a complex listview item layout with all of the elements being the same dimensions for each listview item with the entire layout taking up the whole width of the screen. So far I have attempted doing this using a linearlayout and found that this is the wrong approach. I have then attempted using a relative layout however this has not worked for me so I hope that someone can point out how I can make this work.
Here is a diagram of what I am trying to build.
Here is some more details about the diagram:
Only elements 5 and 6 have the same content for every list item. The
rest of elements all will have different text however the layout
should always be the same size.
Element 4 should only be 2 lines. Elements 1, 2 and 3 should only be 1
line.
Element 2 should be aligned left and element 3 should be aligned
right.
Element 2 and 3 should each be half of the width of element 4.
Here is my attempt at this layout using a RelativeLayout.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="2dp">
<TextView
android:id="#+id/txtRaceNumber"
android:layout_width="20dp"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:layout_gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" />
<TextView
android:id="#+id/txtRaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_toRightOf="#id/txtRaceNumber"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/txtRaceClass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="1"
android:ellipsize="marquee"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toRightOf="#id/txtRaceNumber" />
<TextView
android:id="#+id/txtRaceStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="1"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/txtRaceClass" />
<ImageButton
android:id="#+id/btnTracklist"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#null"
android:paddingRight="8dip"
android:focusable="false"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/txtRaceStartTime" />
<ImageView
android:src="#drawable/go"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/btnTracklist" />
</RelativeLayout>
Using this RelativeLayout all of the elements appear scrambled within the layout.
How can I get all of these elements to align as I have shown in the Diagram?
Is this what you need?
<LinearLayout
android:id="#+id/lin1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
<TextView
android:id="#+id/txtRaceNumber"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:text="TExt1"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="#+id/lin1"
android:layout_toLeftOf="#+id/lin3">
<TextView
android:id="#+id/txtRaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text4"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/txtRaceClass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="text2"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/txtRaceStartTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="text3"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/lin3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/btnTracklist"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#null"
android:focusable="false"
android:paddingRight="8dip" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:src="#drawable/ic_launcher" />
</LinearLayout>
try this code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="90dp"
android:gravity="center|left"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="left|center"
android:layout_gravity="center"
android:gravity="center"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left|center"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left|center"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_weight="1"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_weight="1"
android:text="TextView"
android:textColor="#FFFFFF"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left|center" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginRight="3dp"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_marginRight="3dp"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center"
android:src="#drawable/ic_launcher"
/>
</LinearLayout>
</LinearLayout>
I have managed to get the desired layout using weightSum on the main layout.
Here is the code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/twolinechecked"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:maxHeight="?android:attr/listPreferredItemHeight"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:orientation="horizontal"
android:weightSum="1"
android:descendantFocusability="blocksDescendants">
<TextView
android:id="#+id/txtRaceNumber"
android:layout_width="40dip"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center"
android:layout_gravity="center"
android:paddingRight="5dip"
android:paddingLeft="5dip"
android:textStyle="bold" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginLeft="6dip">
<TextView
android:id="#+id/txtRaceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="#+id/linearTextInner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical|center_horizontal">
<TextView
android:id="#+id/txtRaceClass"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:maxLines="1"
android:ellipsize="marquee"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/txtRaceStartTime"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:maxLines="1"
android:layout_alignParentRight="true"
android:gravity="right" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="#+id/btnTracklist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:layout_marginLeft="5dip"
android:paddingRight="8dip"
android:layout_gravity="center_vertical|center_horizontal" />
<ImageView
android:src="#drawable/go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_alignParentRight="true" />
</LinearLayout>
Follow below structure I feel you can achieve what you want use weight and weightSum.
<LinearLayout orientation="horizontal">
<LinearLayout>
<TextView/>
</LinearLayout>
<LinearLayout orientation="vertical">
<TextView/>
<LinearLayout orientation="horizontal">
<TextView/>
<TextView/>
</LinearLayout>
<ImageButton/>
<ImageView/>
</LinearLayout>
EDIT
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:baselineAligned="false"
android:orientation="horizontal"
android:padding="2dp"
android:weightSum="1" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.2" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:orientation="vertical"
android:weightSum="1" >
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.7"
android:gravity="center" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="0.3"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center" />
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.15" />
<ImageButton
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="0.15" />
</LinearLayout>
I have given my layout xml below.
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:stretchColumns="1" >
<TableRow>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:src="#drawable/no_image" />
<TableLayout
android:layout_width="match_parent"
android:layout_gravity="left"
android:stretchColumns="0" >
<TableRow>
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_weight="1"
android:background="#drawable/backwithborder"
android:ems="5" />
</TableRow>
<TableRow android:layout_height="match_parent" >
<EditText
android:id="#+id/editText1"
android:layout_weight="1"
android:layout_height="35dip"
android:background="#drawable/backwithborder" />
<ImageView
android:layout_width="wrap_content"
android:layout_gravity="right"
android:src="#drawable/ic_menu_down" />
</TableRow>
</TableLayout>
</TableRow>
<View
android:layout_height="2dip"
android:background="#color/list_seperator" />
<TableRow>
<Button
android:id="#+id/xBtnContacts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Pick Contacts" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#color/list_seperator" />
</TableLayout>
try out somthing like this
<?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" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#drawable/ic_launcher" />
<TableLayout
android:id="#+id/table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/imageView1" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="5" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="35dip"
android:layout_weight="1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="#android:drawable/ic_menu_add" />
</TableRow>
</TableLayout>
<Button
android:id="#+id/xBtnContacts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/table"
android:text="Pick Contacts" />
<View
android:layout_height="2dip"
android:layout_width="fill_parent"
android:layout_below="#id/xBtnContacts"
android:background="#ff0000"/>
</RelativeLayout>
try moving the gravity and setting your width and height to fill_parent
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:src="#drawable/no_image" />
The spacing between image and edit text is due to "Pick Contacts" as in table layout widht of one row depend on other ........ (try with give the width 40dp to button for test it)
I 'll suggest to use the Linear layout and Relative layout to make this UI....