屏幕底部的定位按钮

时间:2015-12-30 17:52:48

标签: android xml android-layout

我正在尝试使用下面的xml创建一个非常简单的屏幕,屏幕底部有一个按钮(此时没有任何其他内容)。它在Android Studio中看起来很好但是当我在手机上运行时,按钮不可见(可能在屏幕外)。有什么想法吗?

<?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:text="Send"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:id="@+id/button2" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

您可能更喜欢LinearLayout,使用layout_gravity="bottom"属性会将其设置为屏幕底部:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<Button
    android:text="Send"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity_layout="bottom"
    android:id="@+id/button2" />
</LinearLayout>
相关问题