Andy D
Andy D

Reputation: 125

Android Studio: I can’t make button be at the bottom of screen

I marked marked by red how it supposed to be, I need to change properties of current elements of Component Tree, I wouldn’t like to remove them or add another. enter image description here

Text view:

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

Upvotes: 1

Views: 1692

Answers (2)

Manoranjan
Manoranjan

Reputation: 1015

If you want to give a button below your screen then use a Relative layout as parent and give the attribute alignparentbottom, if you insist to use LinearLayout as parent then use this,

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

NOTE: Please do a Gradle sync and even after if it is not loading, then change your Gradle

    compileSdkVersion 26
buildToolsVersion '26.0.2'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'

Upvotes: 5

Mark Samy
Mark Samy

Reputation: 148

Why using horizontal linear layout as a top layer. You can use Relative Layout as a top Layer and in the inner Relative Layout you can add the property android:layout_alignParentBottom="true"

Upvotes: 1

Related Questions