Android Studio:我不能让按钮位于屏幕底部

And*_*y D 1 layout user-interface android android-layout android-studio

我用红色标记它应该如何,我需要更改组件树当前元素的属性,我不想删除它们或添加另一个。 在此处输入图片说明

文本视图:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/topLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">
    <com.camera.test.ui.camera.CameraSourcePreview
        android:id="@+id/preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <com.camera.test.ui.camera.GraphicOverlay
            android:id="@+id/graphicOverlay"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <RelativeLayout
            android:id="@+id/content"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/footer"
            android:gravity="center">
            <Button
                android:id="@+id/button"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentRight="true"
                android:layout_centerHorizontal="true"
                android:background="@drawable/icon"
                android:onClick="Categories"
                android:text="BUTTON"
                android:textColor="#228496"
                android:textSize="21sp" />
        </RelativeLayout>
    </com.camera.test.ui.camera.CameraSourcePreview>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Man*_*jan 5

如果您想在屏幕下方提供一个按钮,则使用相对布局作为父级并赋予属性 alignparentbottom,如果您坚持使用 LinearLayout 作为父级,则使用此,

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="bottom|center_horizontal"
    android:orientation="vertical">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

注意:请进行 Gradle 同步,即使它没有加载,然后更改您的 Gradle

    compileSdkVersion 26
buildToolsVersion '26.0.2'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
Run Code Online (Sandbox Code Playgroud)