我的可绘制文件夹中有 7 个 xml 文件,用于按大小递减顺序绘制 7 个矩形。每个 xml 文件都是 imageview 的背景资源。这意味着我有 7 个 imageview。
我使用相对布局将它们按尺寸递减的顺序放置在彼此的顶部,以便最小的矩形在顶部。
这是矩形的可绘制 xml 文件之一的示例 xml:-
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFF0000"
android:endColor="#80FF00FF"
android:angle="90"/>
<solid
android:color="#FFFF0000"></solid>
<stroke android:width="1px" android:color="#cccccc" />
<padding android:left="50dp"
android:top="10dp"
android:right="50dp"
android:bottom="10dp" />
<corners android:radius="8dp" />
</shape>
虽然我通过使用属性“android:layout_above”得到了矩形堆栈。但是矩形在一侧对齐。但我希望它们不要在任一侧对齐并在两侧显示为缩小的边缘。
基本上我希望所有矩形都在中心对齐,以便在底部矩形的底部看到顶部矩形的缩小边缘。但我没有找到任何可以帮助我的 imageview 属性。
这是我在水平滚动视图内的相对布局:-
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/desert">
<ImageView
android:id="@+id/camel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
<ImageView
android:id="@+id/puppet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"/>
<ImageView
android:id="@+id/sun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"/>
<ImageView
android:id="@+id/hand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp"
android:layout_marginBottom="100dp"
android:layout_marginTop="150dp"
android:layout_alignParentTop="true"/>
<ImageView
android:id="@+id/stone1"
android:background="@drawable/stone1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:scaleType="center"
android:layout_toRightOf="@id/sun"/>
<ImageView
android:id="@+id/stone2"
android:background="@drawable/stone2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_above="@id/stone1"
android:scaleType="center"
android:layout_toRightOf="@id/sun"/>
<ImageView
android:id="@+id/stone3"
android:background="@drawable/stone3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_above="@id/stone2"
android:scaleType="center"
android:layout_toRightOf="@id/sun" />
<ImageView
android:id="@+id/stone4"
android:background="@drawable/stone4"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_above="@id/stone3"
android:scaleType="center"
android:layout_toRightOf="@id/sun"/>
<ImageView
android:id="@+id/stone5"
android:background="@drawable/stone5"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_above="@id/stone4"
android:scaleType="center"
android:layout_toRightOf="@id/sun" />
<ImageView
android:id="@+id/stone6"
android:background="@drawable/stone6"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_above="@id/stone5"
android:scaleType="center"
android:layout_toRightOf="@id/sun" />
<ImageView
android:id="@+id/stone7"
android:background="@drawable/stone7"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_above="@id/stone6"
android:scaleType="center"
android:layout_toRightOf="@id/sun" />
</RelativeLayout>