我需要构建以下视图:
其中按钮可以是从 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>