【问题标题】:Any Idea how to create this layout in android. and more over how to handle click events of irregular shapes?任何想法如何在 android 中创建此布局。以及如何处理不规则形状的点击事件?
【发布时间】:2014-08-28 16:33:36
【问题描述】:

我想创建一个这样的布局并根据不规则的 sahpes 处理点击事件。但我不知道如何做到这一点,任何帮助将不胜感激。

【问题讨论】:

  • 一种简单的方法是使用 5 张图像(4 个矩形和 1 个圆形位于其他图像之上)。
  • @suitianshi 你能给我一个例子或发布xml文件吗?

标签: android android-layout


【解决方案1】:

使用相对布局。确保圆圈在 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" />

&lt;/RelativeLayout&gt;

【讨论】:

  • 这不是正确的回答方式。添加一些代码,提供更多说明。
  • 非常感谢@Abs
  • 这差不多吧。只需使用图像而不是颜色。
  • @MuhammadZeshan 有帮助吗?
  • 是的,它正在工作,但我不知道如何仅注册圆形区域的点击侦听器。任何想法? @Abs
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-19
  • 2015-11-06
  • 2016-08-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多