This is a great example of where to use style. A style is just a group of common attributes that you want to apply to a large number of objects. For example, you can create a style called buttonStyle using the following code that will do exactly what you want. If you decide that you want to change the margin, you simply change the style. If you decide that you want to make different margin values ββfor phones of different sizes, just create two styles: one for regular, one for large and much more if necessary.
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="buttonStyle"> <item name="android:layout_marginLeft">10dip</item> <item name="android:layout_marginRight">10dip</item> <item name="android:layout_marginTop">10dip</item> <item name="android:layout_marginBottom">10dip</item> </style> </resources>
Then the button code can be simplified to this:
style="@style/buttonStyle"
When you change the style, all buttons will change automatically. You can also create nested styles. See the API for more details.
source share