android - 如何在 android 中的一个布局上显示一半按钮,在另一个布局上显示一半按钮?

标签 android android-relativelayout

我想设计如下图所示的布局:

enter image description here

我尝试使用相对布局来做到这一点,但我没有想出解决方案。对于所有设备屏幕,它应该处于相同的位置。我怎样才能实现它??? 我试过这段代码:

<?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:id="@+id/relative_layout_top"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/obaz" >

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relative_layout_bottom"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relative_layout_top"
        android:background="@drawable/obaz2" >

        <Button
            android:id="@+id/bt_atoz"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="-20dp"

            android:background="@drawable/button_active" />

    </RelativeLayout>

</RelativeLayout>

任何建议将不胜感激。

最佳答案

您可以将 Button 声明放在 RelativeLayout relative_layout_bottom 之外 然后把它放在你喜欢的地方。

例如: 编辑:

<?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" >

    <RelativeLayout
        android:id="@+id/relative_layout_top"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/obaz" >
    </RelativeLayout>

    <Button
        android:id="@+id/bt_atoz"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:background="@drawable/button_active" />

    <RelativeLayout
        android:id="@+id/relative_layout_bottom"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relative_layout_top"
        android:background="@drawable/obaz2" >
    </RelativeLayout>

</RelativeLayout>

关于android - 如何在 android 中的一个布局上显示一半按钮,在另一个布局上显示一半按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17091362/

相关文章:

java - Android - 存储 PIN/密码

android - 从 ViewModel 通知 Activity

java - 单击布局时如何选中复选框?

android - 如何在相对布局中将两个 View 居中?

android - URI 未注册 Android studio 错误

android - 如何在android中使用GPS坐标测量从当前位置到另一个位置的面积

java - 将 ArrayList 内容转换为带逗号的字符串

android - 如何在移动设备中滚动固定菜单的子菜单

android - 相对布局中的循环依赖错误。

android 使 LinearLayout 及其子元素透明