android - RelativeLayout 中的堆叠按钮

标签 android android-layout button

<分区>

我想在 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/

相关文章:

android - 定制的android dumpsys meminfo

java - 像在收据中一样向 TextView 添加点

android - 是否可以将应用程序的横向屏幕截图上传到 Android Market?

java - Android 后退按钮关闭弹出窗口(如果打开)

java - Eclipse Juno red 在 Linux 上最小化和最大化按钮

android - 长按 ListView 和删除对话框

android - 如何以编程方式更改 Android 中连接的 BLE 设备名称?

android - "Hidden"状态栏下可见工具栏

android - RecyclerView 未显示在协调器布局中

java - 重写 AbstractButton.getIcon 的问题