<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/animal_bg"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="300dp">
<!-- 垂直居中center_vertical 水平居中center_rizontal-->
<Button
style="@style/bynStyle"
android:background="@drawable/one"/>
<Button
style="@style/bynStyle"
android:background="@drawable/three"/>
<Button
style="@style/bynStyle"
android:background="@drawable/two"/>
<Button
style="@style/bynStyle"
android:background="@drawable/box"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="10dp">
<Button
style="@style/bynStyle"
android:background="@drawable/box"/>
<Button
style="@style/bynStyle"
android:background="@drawable/four"/>
<Button
style="@style/bynStyle"
android:background="@drawable/four"/>
<Button
style="@style/bynStyle"
android:background="@drawable/two"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginTop="10dp">
<Button
style="@style/bynStyle"
android:background="@drawable/one"/>
<Button
style="@style/bynStyle"
android:background="@drawable/three"/>
<Button
style="@style/bynStyle"
android:background="@drawable/five"/>
<Button
style="@style/bynStyle"
android:background="@drawable/box"/>
</LinearLayout>
</LinearLayout>
报错原因素材资源不一样自己添加替换
样式代码
<style name="bynStyle">
<item name="android:layout_width">80dp</item>
<item name="android:layout_height">80dp</item>
<item name="android:layout_margin">6dp</item>
</style>