Android中可以自定义样式style,在布局文件中可以引用我们自定义的style。
在style.xml文件中自定义样式:
<style name="myStyle">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">0dp</item>
<item name="android:layout_weight">1</item>
<item name="android:padding">10dp</item>
<item name="android:background">#f00</item>
<item name="android:src">@drawable/bd_logo1</item>
<item name="android:layout_marginTop">5dp</item>
</style>
在activity_main.xml中引用我们自定义的style:
<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:orientation="vertical"
android:padding="10dp" >
<ImageView
style="@style/myStyle"/>
<ImageView
style="@style/myStyle"/>
<ImageView
style="@style/myStyle"/>
</LinearLayout>
运行结果: