How to edit the position of Floating buttom

Asked

Viewed 144 times

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 the 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 Gravity layout option besides not being suggested has no effect writing manually.

  • The layout in which the button is inserted may be influencing behavior. Add the full layout.

  • I didn’t realize I wasn’t visible

1 answer

0

Change the root layout to one CoordinatorLayout or LinearLayout or FrameLayout and put on both Constraintlayout and Floatingactionbutton as children. Leave 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>
  • Thank you very much, it worked perfectly :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.