<分区>
我想在 Android 中堆叠多个(圆形)按钮。这就是我想要实现的目标:http://imageshack.us/photo/photo/19/0gp1.jpg/
我试图将多个按钮放在一个 RelativeLayout 中(并将它们的位置设置为绝对位置)但这并没有给出我想要实现的结果,因为按钮在不同的密度/屏幕上没有正确的位置尺寸。有没有人有过这种按钮/布局的经验?我该怎么做才能达到这个结果?
<分区>
我想在 Android 中堆叠多个(圆形)按钮。这就是我想要实现的目标:http://imageshack.us/photo/photo/19/0gp1.jpg/
我试图将多个按钮放在一个 RelativeLayout 中(并将它们的位置设置为绝对位置)但这并没有给出我想要实现的结果,因为按钮在不同的密度/屏幕上没有正确的位置尺寸。有没有人有过这种按钮/布局的经验?我该怎么做才能达到这个结果?
最佳答案
在 RelativeView 中创建它,首先构建 btn1,然后是 btn2,然后是另一个 RelativeLayout btn3 和 btn4,最后是 btn 5,然后给出背景图像。您应该做的就是照顾好它们的尺寸。
编辑:
这是我写的代码:
<?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"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<Button
android:id="@+id/btn1"
android:layout_width="250dp"
android:layout_height="180dp"
android:text="btn1" />
<Button
android:id="@+id/btn2"
android:layout_width="250dp"
android:layout_height="70dp"
android:layout_below="@+id/btn1"
android:text="btn2" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<Button
android:id="@+id/btn3"
android:layout_width="150dp"
android:layout_height="75dp"
android:text="btn3" />
<Button
android:id="@+id/btn4"
android:layout_width="150dp"
android:layout_height="75dp"
android:layout_below="@+id/btn3"
android:text="btn4" />
<Button
android:id="@+id/btn5"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:text="btn5" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
关于android - RelativeLayout 中的堆叠按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20580413/