How to edit the position of Floating buttom

0

This is the XML of my layout

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".PostScreen">


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_gravity="bottom|end"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:clickable="true"
        android:focusable="true"
        app:srcCompat="@color/colorAccent"
        android:src="@drawable/add_symbol"
        android:onClick="addPost"/>

</android.support.constraint.ConstraintLayout>

Below is Gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.cliente.postit"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:design:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation 'com.android.support:design:27.1.1'

Note: The layout gravity option, in addition to not being suggested, has no manual writing effect.

    
asked by anonymous 08.05.2018 / 04:12

1 answer

0

Change the root layout to a CoordinatorLayout or LinearLayout or FrameLayout and put both the ConstraintLayout and the FloatingActionButton as children. Leave the fab with android:layout_gravity="bottom|end" .

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".PostScreen">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- possível novo conteúdo, RecyclerView por exemplo -->

    </android.support.constraint.ConstraintLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_gravity="bottom|end"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:clickable="true"
        android:focusable="true"
        app:srcCompat="@color/colorAccent"
        android:src="@drawable/add_symbol"
        android:onClick="addPost"/>

</android.support.design.widget.CoordinatorLayout>
    
09.05.2018 / 20:59