1

i try my layout code and the BottomAppBar is not showing perfectly i search everywhere but found no question about it.

enter image description here i tried this on Android Studio 3.4 my gradle dependencies are

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.google.android.material:material:1.0.0-beta01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
    implementation 'androidx.vectordrawable:vectordrawable:1.0.0-beta01'
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.squareup.picasso:picasso:2.71828'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
    implementation 'com.github.bumptech.glide:glide:4.9.0'

}

Code i use in home_bottomappbar.xml

<androidx.coordinatorlayout.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">
    <com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bottom_app_bar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_gravity="bottom"
            app:backgroundTint="@color/colorPrimaryDark"
            app:fabAlignmentMode="center"
            app:fabAttached="true"
            app:fabCradleDiameter="0dp"
            app:fabCradleVerticalOffset="10dp" />
     <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_anchor="@id/bottom_app_bar"
            app:backgroundTint="@color/colorPrimary"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Faisal Amin
  • 91
  • 1
  • 5

2 Answers2

0

Replace the Coordinator layout with Relative or Liner Layout. It will work fine.

Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81
  • LinearLayout or Rellative also not working. I don't know why that code is not work in this project. it working perfect in my other projects – Faisal Amin Aug 24 '19 at 08:01
  • avoid using the `coordinator` layout in nested layouts, your `coordinator` layout should be parent/root layout and set layout anchors. – Kiran Maniya Aug 25 '19 at 06:53
0

I was having the same problem for a while too

The solution is to change the width of the BottomAppBar to fill_parent, it should work fine now :)