Auto / dynamic margin in Android layout

I was wondering if it is possible to set an automatic / dynamic field (padding?) Between elements in an Android layout without having to do this programmatically?

For example, let's say there is a horizontal LinearLayout that is set to android:layout_width="fill_parent"and contains five elements. Is there a parameter that evenly divides the remaining LinearLayout empty space into the fields of the children?

See image http://img63.imageshack.us/img63/8/margin.png

Thanks for any help!

+3
source share
2 answers

You can use view dividers as a field with the layout weight set on them.

<LinearLayout ...>
    <View id=marginLeft android:layout_weight="1"/>

    <Element1/>
    <Element2/>
    <Element3/>
    <Element4/>
    <Element5/>

    <View id=marginRight android:layout_weight="1"/>
</LinearLayout>

. , XML :)

-

. , - ( ).

+1
0

Source: https://habr.com/ru/post/1758888/


All Articles