I have problem with layout (buttons) in Andoid. What I want is to display buttons inside ScrollView but the ScrollView must be below a RelativeLayout or with other words, the first two buttons from the ScrollView are not displayed on my phone..
here is the picture:
here is my layout:
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:textAppearance="?android:textAppearanceLarge" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="58.0dip" android:text="#string/naziv" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scrollView" >
<LinearLayout android:layout_gravity="center" android:orientation="vertical" android:paddingLeft="30.0dip" android:paddingTop="90.0dip" android:paddingRight="30.0dip" android:paddingBottom="20dp" android:layout_width="fill_parent" android:layout_height="wrap_content">
<Button android:id="#+id/button0" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_veter" />
<Button android:id="#+id/button4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_plimovanje" />
<Button android:id="#+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_trenutni_podatki" />
<Button android:id="#+id/button5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_video" />
<Button android:id="#+id/button2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_mbp" />
<Button android:id="#+id/button10" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_wsg"/>
<Button android:id="#+id/button11" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_ath" />
<Button android:id="#+id/button12" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_sts" />
<Button android:id="#+id/button13" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_w" />
<Button android:id="#+id/button14" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_dotb" />
<Button android:id="#+id/button15" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_ast" />
<Button android:id="#+id/button16" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_caw" />
<Button android:id="#+id/button17" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="#string/gumb_pado" />
</LinearLayout>
</ScrollView>
</LinearLayout>
How to diplay a ScrollView below text "morska bioloska postaja..."?
thank you
You need to remove android:layout_gravity="center" from the LinearLayout inside the ScrollView. You might also want to remove its android:paddingTop="90.0dip".
add this to your scrollview:
android:layout_below = "#id/textView1"
this should add the scroll below your textView, and remove this:
android:layout_height="fill_parent"
and replace by this:
android:layout_height="wrap_content"
Related
I need to line buttons up horizontally, however, my buttons are appearing vertically. They are all stacked up on top of each other.. do you know how I can do this horizontally?
<TableLayout
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="88dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<Button android:layout_weight="1" />
<Button android:layout_weight="1" />
<Button android:layout_weight="1" />
<Button android:layout_weight="1" />
</TableLayout>
Using Linear layout you can easily represent your button in horizontally.
<LinearLayout
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<Button android:layout_weight="1" />
<Button android:layout_weight="1" />
<Button android:layout_weight="1" />
<Button android:layout_weight="1" />
</LinearLayout>
You have not identified a TableRow for your TableLayout. Imagine how a table is created, row's go horizontally and columns go vertically.
Fixing your code would look something like this
<TableLayout
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="88dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button android:layout_weight="1" />
<Button android:layout_weight="1" />
<Button android:layout_weight="1" />
<Button android:layout_weight="1" />
</TableRow>
</TableLayout>
Alternatively, to make things easier, I would recommend using a LinearLayout with the orientation set to horizontal.
Use a linearlayout as follows:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#646464"
android:gravity="center|center_vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<Button
android:id="#+id/inner_artist_profile"
android:layout_width="60dp"
android:layout_height="25dp"
android:text="Profile"
android:textColor="#AEAEAE"
android:background="#drawable/sub_nav_left" />
<Button
android:id="#+id/inner_artist_news"
android:layout_width="60dp"
android:layout_height="25dp"
android:text="News"
android:textColor="#AEAEAE"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/inner_artist_profile"
android:background="#drawable/sub_nav_middle" />
<Button
android:id="#+id/inner_artist_events"
android:layout_width="60dp"
android:layout_height="25dp"
android:text="Events"
android:textColor="#AEAEAE"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/inner_artist_news"
android:background="#drawable/sub_nav_middle" />
<Button
android:id="#+id/inner_artist_videos"
android:layout_width="60dp"
android:layout_height="25dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/inner_artist_events"
android:background="#drawable/sub_nav_middle"
android:text="Videos"
android:textColor="#AEAEAE" />
<Button
android:id="#+id/inner_artist_albums"
android:layout_width="60dp"
android:layout_height="25dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/inner_artist_videos"
android:background="#drawable/sub_nav_right"
android:text="Albums"
android:textColor="#AEAEAE" />
</RelativeLayout>
this is from a working project modify id's according to need
Instead of a TableLayout, I think you should use a LinearLayout with a WeightSum. To distribute the widths of the 4 buttons evenly, set their widths to 0 and their weight to 1. Then set the weight sum of the LinearLayout to 4 (the number of buttons). Like this:
<LinearLayout
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="88dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal"
android:weightSum="4">
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1" />
<Button
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="1" />
</LinearLayout>
There are many ways to do this.Please check following is one of the way
<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:weightSum="4" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
Add TableRow to TableLayout and here is the working code
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="88dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal" >
<Button android:layout_weight="1" />
<Button android:layout_weight="1" />
<Button android:layout_weight="1" />
<Button android:layout_weight="1" />
</TableRow>
</TableLayout>
Or encapsulate the Button objects within a TableRow tag e.g
<TableRow>
<Button></Button>
</TableRow>
In my screen I am having 3 buttons and in next row below those buttons I am having 3 names (name corresponding to those buttons) but my problem is that when ever name changes then size of buttons also changes but I do want to fix the size of buttons here is my code please help me
<TableLayout android:background="#drawable/toptab"
android:layout_width="fill_parent" android:id="#+id/tableLayout"
android:layout_height="wrap_content"
android:stretchColumns="1" android:gravity="center_vertical"
android:layout_alignParentBottom="true">
<TableRow>
<ImageButton android:id="#+id/btnPrev" android:background="#drawable/imgPrev"
android:layout_marginLeft="5dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<ImageButton android:id="#+id/btnRefresh"
android:layout_gravity="center" android:background="#drawable/refreshbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ImageButton android:id="#+id/btnNext"
android:background="#drawable/imgNext"
android:layout_width="5dp"
android:layout_height="20dp"
android:layout_marginRight="5dp" />
</TableRow>
<TableRow >
<TextView android:id="#+id/prev" android:text="Hk" android:layout_marginLeft="5dp" />
<TextView android:id="#+id/refresh" android:text="Refresh" android:layout_gravity="center" />
<TextView android:id="#+id/next" android:text="RS" android:layout_marginRight="5dp" />
</TableRow>
</TableLayout>
If you want to avoid fixing button size, then I would recommend using different layout than TableLayout, maybe RelativeLayout and TextViews with property alignBaseline or LinearLayout with weight properties could do the trick.
You should use linearlayout instead of table layout and use Weight property for aligning buttons and text view in equal dimensions, so here if you write more text in text view , button size will not increase. Also you can add more buttons in same manner. Below is the XML file and screen shot.
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_weight="1" android:gravity="center_horizontal">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextViewTextTextViewTextTextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_weight="1" android:gravity="center_horizontal">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_weight="1" android:gravity="center_horizontal">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
(i have put the code at the end of my post)
i would like to make a hidden menu.
I don't know if i take the good way.
I have some button visible, some invisible button and at the an another visible button.
One of the button in first layout have to set visible the hidden buttons.
I would like to have the last button just after the first bunch.
But like i have put invisible the Layout so i have an empty space.
I would like when i pressed the button for set visible that the last button go down.
I hope you will understand want i want to do and what i have done.
<?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:background="#drawable/fond"
>
<ImageView
android:id="#+id/imageView1"
android:contentDescription="#string/desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/top"
android:layout_gravity="top"
android:adjustViewBounds="true"
/>
<LinearLayout
android:layout_below="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/fond2"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="3"
>
<Button
android:id="#+id/button_garçon"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/Bg"
android:background="#drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionGarçon"
/>
<Button
android:id="#+id/button_mixte"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/Bm"
android:background="#drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionMixte"
/>
<Button
android:id="#+id/button_fille"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/Bf"
android:background="#drawable/button_purple"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionFille"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1"
>
<Button
android:id="#+id/button_param"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Bp"
android:background="#drawable/button_green"
android:layout_weight="1"
android:textColor="#ffffff"
android:onClick="actionParametre"
/>
</LinearLayout>
<!-- invisible -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="invisible"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Tq"
android:textColor="#000000"
/>
<EditText android:id="#+id/edit_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/Emc"
android:singleLine="true"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Tpre"
android:textColor="#000000"
/>
<EditText android:id="#+id/edit_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/Epre"
android:singleLine="true"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Tsuf"
android:textColor="#000000"
/>
<EditText
android:id="#+id/edit_message"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/Esuf"
android:singleLine="true"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Tl"
android:textColor="#000000"
/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="100"
>
<Button android:id="#+id/button_court"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Blc"
android:layout_weight="25"
android:background="#drawable/button_purple"
android:textColor="#ffffff"
android:onClick="actionCourt"
/>
<Button android:id="#+id/button_moyen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Blm"
android:layout_weight="25"
android:background="#drawable/button_purple"
android:textColor="#ffffff"
android:onClick="actionMoyen"
/>
<Button android:id="#+id/button_long"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Bll"
android:layout_weight="25"
android:background="#drawable/button_purple"
android:textColor="#ffffff"
android:onClick="actionLong"
/>
<Button android:id="#+id/button_tous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Blt"
android:layout_weight="25"
android:background="#drawable/button_purple"
android:textColor="#ffffff"
android:onClick="actionTous"
android:state_pressed="true"
/>
</LinearLayout>
<Button android:id="#+id/button_orig"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Bo"
android:background="#drawable/button_purple"
android:textColor="#ffffff"
android:onClick="actionOrigine"
/>
</LinearLayout>
<!-- /invisible -->
<Button android:id="#+id/button_recher"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Br"
android:background="#drawable/button_green"
android:textColor="#ffffff"
android:onClick="actionRecherche"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Thanks in advance.
If I understand correctly you want to use android:visibility="gone" so that what ever you set to "gone" does not occupy any space on the layout.
Basically, instead of android:visibility="invisible" you should use android:visibility="gone"
See if that works.
I am making an android application that uses these views:
(Root) - LinearLayout
(Child of root) - ListView + 3 other linearlayouts beneeth that listview. But once i add to many items to the listview, the layouts are being placed outside of the screen. Which i don't want to. How can i make this happen? So that all of the three linearlayouts stay on the screen, at the bottom??? Please help and thanks in advance!
My screen XML 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="fill_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<TextView
android:id="#+id/NotesWelcomeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/NotesWelcomeText" />
<ListView
android:id="#+android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView
<LinearLayout
android:id="#+id/DeleteAllItemsFromListViewLinearLayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" >
<Button
android:id="#+id/CancelButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Cancel" />
<Button
android:id="#+id/DeleteAllButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Delete" />
</LinearLayout>
<LinearLayout
android:id="#+id/DeleteItemFromListViewLinearLayout"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="invisible" >
<Button
android:id="#+id/CancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Cancel" />
<Button
android:id="#+id/DeleteButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/Delete" />
</LinearLayout>
<LinearLayout
android:id="#+id/AddItemToListViewLinearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" >
<EditText
android:id="#+id/AddItemToListViewEditText"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_weight="1" >
</EditText>
<Button
android:id="#+id/AddItemToListViewButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Add" />
</LinearLayout>
</LinearLayout>
Try this, you'll have to add the string references and background again, I removed them so I wouldn't have errors
<?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">
<TextView android:id="#+id/NotesWelcomeTextView"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="NotesWelcomeText" />
<ListView android:id="#+android:id/list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_above="#+id/AddItemToListViewLinearLayout"
android:layout_below="#+id/NotesWelcomeTextView">
</ListView>
<LinearLayout android:id="#+id/DeleteAllItemsFromListViewLinearLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:visibility="invisible"
android:layout_alignParentBottom="true">
<Button android:id="#+id/CancelButton2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Cancel" />
<Button android:id="#+id/DeleteAllButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Delete" />
</LinearLayout>
<LinearLayout android:id="#+id/DeleteItemFromListViewLinearLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:visibility="invisible"
android:layout_alignParentBottom="true">
<Button android:id="#+id/CancelButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Cancel" />
<Button android:id="#+id/DeleteButton" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Delete" />
</LinearLayout>
<LinearLayout android:id="#+id/AddItemToListViewLinearLayout"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:visibility="gone" android:layout_alignParentBottom="true">
<EditText android:id="#+id/AddItemToListViewEditText"
android:layout_width="250dp" android:layout_height="wrap_content"
android:layout_weight="1">
</EditText>
<Button android:id="#+id/AddItemToListViewButton"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:text="Add" />
</LinearLayout>
Give your ListView a weight of 0 and set its height to 0. This will tell the ListView to only take up the space that is not use by other views.
<ListView ...
android:layout_weight="0"
android:layout_height="0"
...
/>
I have a problems with my layout_margin. I want to make my layout look like that:
(with "a" is margin)
My problems is, when i build my layout in other screen size, it look like that:
How can i make it beautiful with different screen size? This is my layout:
<LinearLayout
android:id="#+id/footer_result_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/btn_recommendtion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/coodinate" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginTop="20dip"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/btn_facebook"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_margin="5dip"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/fb" />
<ImageView
android:id="#+id/btn_mixi"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_margin="5dip"
android:layout_weight="1"
android:adjustViewBounds="true"
android:src="#drawable/mixi" />
</LinearLayout>
</LinearLayout>
Try using a relative layout.
Here is an example using buttons. You can swap out the values of the buttons with your image views, and adjust your margins as needed. This should center the buttons, with the same margins on any screen.
<Button
android:id="#+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:text="BUTTON 1"
android:layout_centerHorizontal="true"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="#+id/btn_1"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dip"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_margin="5dip"
android:text="BUTTON 2" />
<Button
android:id="#+id/btn_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_margin="5dip"
android:text="BUTTON 3" />
</LinearLayout>
It looks like this:
You'll need to use RelativeLayout for that.
Center button1 with android:layout_alignParentTop="true" and align it in the parent top with android:layout_centerHorizontal="true and work from there.
The code:-
<?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">
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:layout_margin="10dip"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"/>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:layout_margin="10dip"
android:layout_alignParentLeft="true"
android:layout_below="#+id/button1"/>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:layout_margin="10dip"
android:layout_alignParentRight="true"
android:layout_below="#+id/button1"/>
</RelativeLayout>
Considering the a=10