简体   繁体   English

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

[英]How to show a button half on one layout and half on another layout in android?

I want to design a layout like the image below: 我想设计一个如下图所示的布局:

在此处输入图片说明

I tried to do it using Relative layout but I did not come up with a solution. 我尝试使用相对布局来实现,但是我没有提出解决方案。 It should be in the same position for all device screen. 对于所有设备屏幕,它应该位于相同的位置。 How can I achieve it??? 我该如何实现??? I tried this code: 我尝试了这段代码:

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

Any suggestion will be appreciated. 任何建议将不胜感激。

You can put the Button declaration outside of your RelativeLayout relative_layout_bottom and then place it where you like. 您可以将Button声明放在RelativeLayout relative_layout_bottom之外,然后将其放置在所需的位置。

For example: Edit: 例如:编辑:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将布局按钮设计成一半一种颜色,另一半 - how to design layout button to be half one color, half other 如何在滑动一个布局一半而另一个布局一半时应可见的布局? - how to view the layouts while swiping one layout half and another layout half should be visible? 将按钮一半放在一个布局父级中,另一半放在另一个布局中 - Place buttons half in one layout parent and half in another 如何在android坐标布局中半重叠frameLyout - How to half overlap frameLyout in android coordinate layout 如何在android约束布局中半重叠图像 - How to half overlap images in android constraint layout 如何在线性布局中制作一半的框架布局和一半的网格布局? - How to make in Linear layout half Frame Layout and half Grid Layout? 如何允许半个SupportMapFragment和半线性布局? - How to allow for half SupportMapFragment and half linear layout? Android 布局:宽度为父级的一半 - Android Layout: width half of parent 如何在父母布局的右上角添加两个浮动操作按钮(一半为内部布局,一半为外部),并在单击时显示 - How to add two floating action button on top-right of parrent layout (half insidelayout, and half outside), and show on click 如何在半屏上进行布局 - how to make a layout on half screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM