1

我需要构建以下视图:

在此处输入图像描述

其中按钮可以是从 java 代码访问的常规按钮findViewById()方法从 java 代码访问的常规按钮。

我不确定我是否可以使用LayerList做到这一点来做到这一点,或者我是否需要从头开始实现自定义视图?任何人都可以提出一些我可以遵循的路径来实现这一目标吗?

更新

现在我有这个:

在此处输入图像描述

我现在需要做的是: - 隐藏圈外的内容;- 只有 cicle 内的部分按钮应该触发onClick事件。

我应该使用自定义视图组来做到这一点吗?我试过了,但我无法在按钮顶部绘制圆圈(应该可以在onDraw()方法中这样做吗?)......

这是我的代码:

main_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <include layout="@layout/custom_layout" />
    </LinearLayout>

</RelativeLayout>

custom_layou.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:id="@+id/buttons_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="14dp"
        android:paddingBottom="10dp"
        android:background="#CC0000FF"
        android:orientation="vertical">

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button2" />

        <Button
            android:id="@+id/button3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button3" />

        <Button
            android:id="@+id/button4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button4" />
    </LinearLayout>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignTop="@+id/buttons_layout"
        android:layout_alignLeft="@+id/buttons_layout"
        android:layout_alignBottom="@+id/buttons_layout"
        android:src="@drawable/circle_foreground" />

</RelativeLayout>

circle_foreground.xml

<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="100dp"
android:thickness="0dp"
android:useLevel="false" >

<solid android:color="@android:color/transparent" />

<stroke android:width="4dp"
    android:color="#000000"/>

</shape>
4

2 回答 2

1

你必须结合两件事:

  1. ImageView通过用一个(上层)覆盖按钮(下层)来构建布局,其中有一个洞。看这里,怎么做。这两层可以定义为FrameLayout

  2. 现在,您必须将圆圈上的所有触摸都委托给按钮。这应该可以通过TouchListenerImageView. 如果Touchlistener触摸在圆圈外,则返回 true,否则返回 false。返回 false 时,Android 应该将触摸向下传递到下一层,即带有按钮的层。

总而言之,我希望最终的效果值得付出努力,因为这似乎需要大量的工作和测试工作。

于 2013-12-29T20:42:59.257 回答
0

您可以使用 6 个不同的 imageview 并在 relativelayout 中组合成一个圆形 imageview,在每个 imageview 中设置它们的 onclicklistener 以便您可以做您想做的事情

于 2013-12-26T01:23:36.673 回答