我正在尝试在我的 Android 应用程序中创建类似的主菜单设计,正如您在我的附件中看到的那样。
问题是,菜单按钮不是水平的,而是倾斜的,并且彼此部分重叠。
我在RelativeLayout中使用ImageButton尝试了类似的方法:
<ImageButton
android:id="@+id/simpleImageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu1"/>
<ImageButton
android:id="@+id/simpleImageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/simpleImageButton1"
android:src="@drawable/menu2"/>
但是由于图像不是水平的,我需要将每个图像存储为具有透明底部和上部的水平图像,但是,这会导致这些部分也可单击,并且由于它们重叠,两个可单击部分将有碰撞。
有什么好的解决方案可以实现这项工作吗?
由于此菜单将被修复,因此不会添加更多项目,我还想将其作为一个背景图像,也许以某种方式为每个按钮的一部分制作不可见按钮,或者以某种方式映射每个可点击区域。
但是,我还是宁愿采用 ImageButtons 方式或更简单的方式。
您可以尝试使用 FrameLayout,将多个按钮放置在所需的角度并相互重叠。使用属性
android:rotation
和 android:layout_margin
来控制按钮之间的角度和重叠。
这是一个例子:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/simpleImageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu1"
android:layout_marginTop="50dp"
android:layout_marginLeft="50dp"
android:background="@null"
android:foreground="?android:attr/selectableItemBackground"
android:rotation="15" />
<ImageButton
android:id="@+id/simpleImageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu2"
android:layout_marginTop="150dp"
android:layout_marginLeft="50dp"
android:background="@null"
android:foreground="?android:attr/selectableItemBackground"
android:rotation="-10" />
<ImageButton
android:id="@+id/simpleImageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/menu3"
android:layout_marginTop="300dp"
android:layout_marginLeft="50dp"
android:background="@null"
android:foreground="?android:attr/selectableItemBackground"
android:rotation="15" />
</FrameLayout>