侧面按钮在屏幕边缘

时间:2015-07-08 22:08:48

标签: android

我试图在屏幕边缘添加一个按钮,如下所示:

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

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_centerVertical="true"
        android:rotation="270"
        android:text="Button" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

使用RelativeLayout访问layout_alignParentEnd的属性Button。如果您的根布局是RelativeLayout,那么使用它,如果不是,您可以将Button包裹在RelativeLayout中并使用该布局。如果选择后一种选项,则需要定位该布局。

<RelativeLayout
    android:id="@id+/wrapper_or_root"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <Button
        android:id="@+id/myButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_gravity="center_vertical|right"
        android:rotation="270"/>
</RelativeLayout>
相关问题