BottomAppBar игнорирует 'layout_gravity', всегда отображается сверху - PullRequest
0 голосов
/ 24 июня 2018

Я пытаюсь внедрить BottomAppBar в свое приложение и не могу отобразить FAB или BottomAppBar внизу.Вот мой макет:

<?xml version="1.0" encoding="utf-8"?>
<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=".dashboard.DashboardActivity">

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_add_white_24dp"
    app:layout_anchor="@id/bottom_bar"/>

<android.support.design.bottomappbar.BottomAppBar
    android:id="@+id/bottom_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/mtrl_bottomappbar_height"
    android:layout_gravity="bottom"
    app:backgroundTint="@color/colorPrimary"
    app:fabAttached="true"
    app:fabCradleVerticalOffset="12dp"
    app:fabAlignmentMode="center"/>

</android.support.constraint.ConstraintLayout>

Однако, это то, что отображается в эмуляторе:

image

Как мневыровнять его по низу?

Ответы [ 4 ]

0 голосов
/ 15 июля 2018

Вы должны попробовать это:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.bottomappbar.BottomAppBar
        android:id="@+id/bottom_bar"
        android:layout_width="0dp"
        android:layout_height="@dimen/mtrl_bottomappbar_height"
        app:backgroundTint="@color/colorPrimary"
        app:fabAlignmentMode="center"
        app:fabAttached="true"
        app:fabCradleVerticalOffset="12dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>
0 голосов
/ 24 июня 2018

ConstraintLayout не использует layout_gravity. Вместо этого используйте:

app:layout_constraintBottom_toBottomOf="parent" 

без наценки.

0 голосов
/ 24 июня 2018

Во-первых, измените макет на LinearLayout и определите ориентацию как вертикальную в нем, а затем поместите свой код в другой LinearLayout, в котором вы можете сделать его marginTop как ваши требования просто внесите эти изменения, он должен работать нормально

<LinearLayout
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=".dashboard.DashboardActivity"
android:orientation="vertical"

>

<LinearLayout
   android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_marginTop="330dp" //mark height accordingly
 >


  \\put your code here



</LinearLayout>


</LinearLayout>

попробуй, у тебя все будет нормально

0 голосов
/ 24 июня 2018

Иногда это зависит и от вашего корневого макета.
для ConstraintLayout попробуйте app:layout_constraintBottom_toBottomOf="parent"

Проверьте этот ответ и для других макетов.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...