0

e.g having the same space between them, not resizing them.

For example : top-20dp-button-20dp-button-20dp (20 is an example, I do not want to use dp)

I tried this with no luck :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:visibility="visible" android:weightSum="3">

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:gravity="center_vertical|center_horizontal"
        android:text="Button" android:layout_weight="1"/>

    <Button
        android:id="@+id/button2"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:gravity="center_vertical|center_horizontal"
        android:text="Button" android:layout_weight="1"/>

    <Button
        android:id="@+id/button3"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:gravity="center_vertical|center_horizontal"
        android:text="Button" android:layout_weight="1"/>

</LinearLayout>

thanks for your help !

Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
Huberte
  • 23
  • 6

3 Answers3

1

You can achieve the affect your looking for by surrounding each button with it's own linear layout and then setting the weights on the new linear layouts to each be one. From there you just need to tweak the button to specify layout_gravity rather than just gravity (layout_gravity position the view with it's parent, gravity positions elements within the view)

The code would look like this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:visibility="visible"
    android:weightSum="3" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <Button
            android:id="@+id/button1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="Button" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <Button
            android:id="@+id/button2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="Button" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <Button
            android:id="@+id/button3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal"
            android:text="Button" />
    </LinearLayout>
</LinearLayout>
CJPresler
  • 63
  • 3
0

Your question is very hard to understand, I understand you are not fluent in English but you need to be more specific. Post an image of the design like what you want. I will take another guess, maybe this is what you were trying to describe:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"  
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:visibility="visible">

    <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="Button 1"
        />

    <Button
        android:id="@+id/button2"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="Button 2"
        />

    <Button
        android:id="@+id/button3"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="Button 3" 
        />

</LinearLayout>

I based this off the only description you provided:

For example : top-20dp-button-20dp-button-20dp

Once again you can use dp, sp, or anything that you want; understand that dp stands for density-independent pixel. Again Supporting Multiple Screens and More Resource Types describe it very well, you will see that dp is relative. It also describes the difference between dp or dip, which is not dpi.

Also notice I changed my padding suggestion to adjusting the margin, I was wrong the first time but with such a vague question it was only a guess. I hope this helps, otherwise post a clear picture of what you hope to achieve. Good luck!

Sam
  • 86,580
  • 20
  • 181
  • 179
  • Please read my quesiton again, i do not want to use dp. I want it stay relative. – Huberte May 11 '12 at 22:34
  • Use whatever units you want... But dp is relative, [Supporting Multiple Screens](http://developer.android.com/guide/practices/screens_support.html) – Sam May 11 '12 at 22:37
  • Sam, just the same, 3 butotns are filling all the space in the vertical layout hwen merging your code with mine – Huberte May 12 '12 at 03:09
  • Really ? I thought I was very fluent in english :) OK will try to explain further. I want to have a vertically or horizontally layout thaht fill the screen. In it I want to have 3 buttons, small one. They should fill the space not with their size, but in an harmonious way. For example if you have 3 buttons with 10 dpi size i na screen of 90 dpi : 20dpi – Huberte May 12 '12 at 09:44
  • 110 dpi for the screen, not only bad in english but in math too :) here's an image : here's an image – Huberte May 12 '12 at 10:01
0

Thanks to Kostya, here's an asnwer :)

<?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">
    <View
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>
<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="button 1"/>

<View
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="button 2"/>

<View
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/>

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="button 3"/>
<View
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"/> 
</LinearLayout>
Huberte
  • 23
  • 6