Only the first nested linear layout is showing up, any idea why? The first textView inside the 2nd linear layout shows up, and the layout is the proper height, but none if it's contents can be viewed.
<?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:orientation="vertical"
android:weightSum="100">
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="42dp"
android:background="#FAFA25"
android:height="200dp"
android:text="#string/hello"
android:textColor="#222222"
android:textSize="20dp" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/width" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number" >
<requestFocus />
</EditText>
</LinearLayout>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="#string/totalWidth"
android:layout_marginRight="10dp" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_height="wrap_content"
android:background="#999999"
android:layout_width="fill_parent"
android:layout_margin="10dp"
android:padding="4dp"
android:weightSum="100" >
<TextView
android:id="#+id/textView5"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="#string/numOne"
android:layout_weight="62"
android:background="#ffffff"
android:gravity="center"
android:textColor="#222222"
android:layout_marginRight="1dp" />
<TextView
android:id="#+id/textView6"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="#string/numTwo"
android:background="#ffffff"
android:layout_weight="38"
android:gravity="center"
android:textColor="#222222"
/>
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Calculate" />
</LinearLayout>
</LinearLayout>
linearLayout3 , orientation is horizontal, in case you are wondering why, default orientation is horizontal. and since textView has layout_width="fill_parent", the next child will not show up.
change the orientation to vertical.
Related
I'm trying to get a form such a way that on each row the TextView is on the left and the EditText is on the right.
The below code works fine for one row, however,r if I have multiple rows then it doesn't draw TextView and EditText on each row but instead tries to jam everything together.
<?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="wrap_content"
android:orientation="horizontal"
android:padding="10dip"
android:background="#FFFFFF"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Full Name"
android:textSize="20dp"
android:layout_weight="1"
android:textColor="#000000"
/>
<EditText
android:id="#+id/name"
android:gravity="center"
android:hint="John Doe"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Age"
android:textSize="20dp"
android:layout_weight="1"
android:textColor="#000000"
/>
<EditText
android:id="#+id/age"
android:gravity="center"
android:hint="age"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
/>
</LinearLayout>
This is what it looks like
There are so many ways to achieve the Layout which you been looking for. You were on track by adding layout_weight="1" in Views. Here's the one which uses your Layout only with little bit of orientation changes.
Explaination:
LinearLayout //ParentView Orientation - Vertical
LinearLayout //childView Orientation - Horizontal
TextView & EditText // Taking equal space with help of layout_weight="1"
LinearLayout //childView Orientation - Horizontal
TextView & EditText // Taking equal space with help of layout_weight="1"
Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip"
android:background="#FFFFFF"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Full Name"
android:textSize="20dp"
android:layout_weight="1"
android:textColor="#000000"
/>
<EditText
android:id="#+id/name"
android:gravity="center"
android:hint="John Doe"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Age"
android:textSize="20dp"
android:layout_weight="1"
android:textColor="#000000"
/>
<EditText
android:id="#+id/age"
android:gravity="center"
android:hint="age"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
// try this way,hope this will help you...
<?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:padding="5dp"
android:background="#FFFFFF">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.40"
android:text="Full Name"
android:textSize="20sp"
android:gravity="right"
android:textColor="#000000"/>
<EditText
android:id="#+id/name"
android:gravity="center"
android:hint="John Doe"
android:layout_width="0dp"
android:layout_weight="0.60"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:layout_marginLeft="5dp">
<TextView
android:layout_width="0dp"
android:layout_weight="0.40"
android:layout_height="wrap_content"
android:text="Age"
android:gravity="right"
android:textSize="20sp"
android:textColor="#000000"/>
<EditText
android:id="#+id/age"
android:gravity="center"
android:hint="Age"
android:layout_width="0dp"
android:layout_weight="0.60"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
I have a layout with a view text views, a table and then some buttons at the bottom.
I wanted the buttons to always be at the bottom regardless of the height of the table so I changed the layout to relative so I could do this.
However this mashed all the textviews and the table into one line. So I put these in a LinearLayout within the RelativeLayout which I thought would fix the problem. Problem now is that only the first TextView and the buttons at the bottom show up. Everything else is missing.
Here is the xml code I am using to define this layout:
<?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="fill_parent"
android:layout_margin="4dip"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<TextView
android:id="#+id/view_meal_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Spaghetti Bolognaise"
android:textSize="25sp" />
<TextView
android:id="#+id/view_meal_type"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dinner"
android:textSize="16sp" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/view_day_calories"
android:text="#string/calories_label"
android:textSize="18sp" />
<TextView
android:id="#+id/view_day_calories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="#string/calories_today_value"
android:textSize="18sp" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="10dip"
android:background="#color/hr" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:stretchColumns="0,1,2" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/meal_table_ingred_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ingredient"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/meal_table_quantity_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/quantity"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/meal_table_calories_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/calories"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="1.0" >
<Button
android:id="#+id/edit_meal_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/edit_meal_label" />
<Button
android:id="#+id/favourite_meal_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/favourite_meal_label" />
</LinearLayout>
</RelativeLayout>
Thanks for your help!
Change
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
to
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
I have a relative layout with two linear layout inside it with two textviews in each of them.
I wanted the textviews to appear horizontally as a row.
The code is given below:
<RelativeLayout
android:id="#+id/linear2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/txtlinear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/esms_parentfees_classtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/esms_parentfees_classdetais"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/esms_parentfees_classdetais"
android:orientation="horizontal" >
<TextView
android:id="#+id/esms_parentfees_datetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/esms_parentfees_datedetais"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
Notes on your XML:
You can't use toRightOf, etc, within a LinearLayout
RelativeLayout's don't have an orientation
This is needed for some reason to show all the XML? Ignore this line
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/esms_parentfees_classtext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
<TextView
android:id="#+id/esms_parentfees_classdetais"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/esms_parentfees_datetext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
<TextView
android:id="#+id/esms_parentfees_datedetais"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5" />
</LinearLayout>
</RelativeLayout>
The easiest way would be to make the outer RelativeLayout a LinearLayout
<LinearLayout
android:id="#+id/linear2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
Then remove any tag like
android:layout_toRightOf="#+id/esms_parentfees_classdetais"
Or, you could just change the tag mentioned above to
android:layout_below="#+id/esms_parentfees_classdetais"
if you need the four textviews in a row its easy to just use a linear layout with the four text views in it (or a table layout) instead of using two linear layouts in a relative layout.
Have a look at this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/txtlinear"
>
<TextView
android:id="#+id/esms_parentfees_classtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="#+id/esms_parentfees_classdetais"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="#+id/esms_parentfees_datetext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="#+id/esms_parentfees_datedetais"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
</LinearLayout>
or
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/txtlinear"
>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/esms_parentfees_classtext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="#+id/esms_parentfees_classdetais"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="#+id/esms_parentfees_datetext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
<TextView
android:id="#+id/esms_parentfees_datedetais"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="hi" />
</TableRow>
</TableLayout>
or if its a compulsion that you need a relative layout with two linear layouts in it you can follow any of the solutions above
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/esms_parentfees_classtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/esms_parentfees_classdetais"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/esms_parentfees_classtext"
/>
</RelativeLayout>
I need to have multiple textviews within a scrollview. I am using a relative layout as a container to all these textviews.
The layout looks fine in portrait orientation, but when in landscape orientation, the textview at the top of the relative layout within the scrollview (tvEx) is not visible. This is only when I test in the emulator for devices that have a small screen. Apart from this minor problem, the layout works perfectly well. Although, this seems to be a minor issue, somehow I am not able to get around it. Kindly help.
The layout file is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#drawable/background" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/header" >
<Button
android:id="#+id/btBack"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/back"
android:visibility="invisible" />
<TextView
android:id="#+id/tvBanner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignBaseline="#+id/btBack"
android:layout_alignBottom="#+id/btBack"
android:layout_alignParentLeft="true"
android:gravity="fill"
android:text="Practice Exam"
android:textColor="#android:color/white"
android:textSize="20sp" />
</LinearLayout>
<RelativeLayout
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/footer"
android:orientation="horizontal" >
<Button
android:id="#+id/btHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/home" />
</RelativeLayout>
<ScrollView
android:id="#+id/ScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/RelativeLayout1"
android:layout_below="#+id/Header"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center" >
<RelativeLayout
android:id="#+id/RelativeLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:gravity="center" >
<TextView
android:id="#+id/tvEx"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentTop="true"
android:text="Congratulations!!"
android:textColor="#android:color/white"
android:textSize="24sp"/>
<TextView
android:id="#+id/tvRes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvEx"
android:gravity="center"
android:text="You passed"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/tvLuck"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvRes"
android:layout_margin="10dp"
android:gravity="center"
android:text="Great going"
android:textColor="#android:color/white"
android:textSize="18sp" />
<LinearLayout
android:id="#+id/lins"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:gravity="center_horizontal"
android:layout_centerHorizontal="true"
android:layout_below="#+id/tvLuck"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tvScore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SCORE:"
android:textColor="#android:color/white"
android:textSize="24sp" />
<TextView
android:id="#+id/tvScoreNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/tvScore"
android:layout_alignBaseline="#+id/tvScore"
android:textColor="#android:color/white"
android:textSize="28sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="#+id/tvCorr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/lins"
android:layout_margin="10dp"
android:layout_marginTop="47dp"
android:gravity="center_horizontal"
android:text="Correct Answers:"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/tvIncorr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvCorr"
android:gravity="center_horizontal"
android:text="Incorrect Answers:"
android:textColor="#android:color/white"
android:textSize="18sp" />
<TextView
android:id="#+id/tvtot"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvIncorr"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="Total Questions:"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I had a similar problem in a ScrollView. Try changing android:gravity="center" to android:gravity="center_horizontal" or removing it completely. Similar to ScrollView hides.
I use tablelayout instead of the custom header title bar
Now my layout like the xml I show below, and I want to put the 2 icon and the text align right, but when I use android:layout_gravity="right" it seems not work, so how can I do it ?
This is my layout xml:
< ? 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" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#4494D1" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right" >
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="简易尺子"
android:textColor="#fff"
android:textSize="25dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="28dp"
android:layout_height="28dp"
android:background="#drawable/android2"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="关于"
android:textColor="#fff" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="vertical" >
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="28dp"
android:layout_height="28dp"
android:background="#drawable/programs"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="帮助"
android:textColor="#fff" />
</LinearLayout>
</TableRow>
</TableLayout>
<SurfaceView
android:layout_width="match_parent"
android:id="#+id/surfaceView1"
android:layout_height="match_parent">
</SurfaceView>
</LinearLayout>
The layout gravity you set is not to affect the positioning of the TextView and the ImageView in the TableRow, rather it will position them in the wrapping LinearLayout which is not quite what you need. I suggest you define the following attribute to your TableLayout:
<TableLayout
android:layout_width="fill_parent"
android:layout_width="wrap_content"
android:stretchColumns="0,1">
This will make the first two columns of the raw expand and thus shrink the rightmost column to the right.
NOTE (IMPORTANT) Currently you do not have a valid layout defined: you have a TableRow in LinearLayout - this is not allowed - you should place the row in TableLayout like the one I have defined.
try 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="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:id="#+id/textView2"
android:text="简易尺子"
android:textAppearance="?android:attr/textAppearanceLarge" />
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/imageButton2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageButton1"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/text2"
android:text="关于"
android:textColor="#fff" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_alignParentRight="true" />
<TextView
android:id="#+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/imageButton2"
android:text="帮助"
android:textColor="#fff" />
</RelativeLayout>
</TableRow>
</TableLayout>
<SurfaceView
android:id="#+id/surfaceView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/tableLayout1" >
</SurfaceView>
</RelativeLayout>