【发布时间】:2014-08-28 16:33:36
【问题描述】:
我想创建一个这样的布局并根据不规则的 sahpes 处理点击事件。但我不知道如何做到这一点,任何帮助将不胜感激。
【问题讨论】:
-
一种简单的方法是使用 5 张图像(4 个矩形和 1 个圆形位于其他图像之上)。
-
@suitianshi 你能给我一个例子或发布xml文件吗?
我想创建一个这样的布局并根据不规则的 sahpes 处理点击事件。但我不知道如何做到这一点,任何帮助将不胜感激。
【问题讨论】:
使用相对布局。确保圆圈在 xml 中的正方形之后,所以它会在它们的前面。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_purple" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/centerLine"
android:orientation="horizontal" >
<ImageView
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:src="@android:color/holo_orange_dark" />
<ImageView
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginLeft="2dp"
android:layout_weight="1"
android:src="@android:color/holo_green_dark" />
</LinearLayout>
<View
android:id="@+id/centerLine"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_centerVertical="true"
android:background="@android:color/holo_purple" />
<LinearLayout
android:id="@+id/bottomSquares"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/centerLine"
android:layout_centerVertical="true"
android:orientation="horizontal" >
<ImageView
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginRight="2dp"
android:layout_weight="1"
android:src="@android:color/holo_red_light" />
<ImageView
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginLeft="2dp"
android:layout_weight="1"
android:src="@android:color/holo_blue_light" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/circle" />
</RelativeLayout>
【讨论】: