Плавающие кнопки Android не установлены в фиксированном положении - PullRequest
0 голосов
/ 08 мая 2018

Я показываю 2 плавающие кнопки в моей активности, но плавающие кнопки устанавливаются в нижней части, когда нет данных для отображения в активности.если в действии отображаются записи, то вместо записей в фиксированной позиции показываются плавающие кнопки

Ниже приведен мой макет активности

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/login_background"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_gravity="center"
        android:background="@color/login_header"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/imgInfo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="5dp"
                android:src="@drawable/info" />

            <ImageView
                android:id="@+id/imgLogout"
                android:layout_width="wrap_content"
                android:layout_height="20dp"
                android:layout_marginStart="290dp"
                android:src="@drawable/logout" />

        </LinearLayout>

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_gravity="center_horizontal|center_vertical"
            android:layout_marginTop="10dp"
            android:src="@drawable/logo1" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="horizontal"
            android:paddingStart="120dp">

            <ImageView

                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:layout_gravity="center_horizontal|center_vertical"
                android:background="@color/login_header"
                android:src="@drawable/userprofile" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:fontFamily="@font/segoeui"
                android:paddingStart="20dp"
                android:text="@string/name"
                android:textColor="@color/white"
                android:textSize="20sp"
                android:textStyle="bold" />

        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/machineLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical">

        </android.support.v7.widget.RecyclerView>

    </LinearLayout>
</LinearLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/search"
    android:layout_width="46dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@drawable/search" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/addNew"
    android:layout_width="46dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@drawable/add" />

Послеснимок экрана enter image description here

Ответы [ 2 ]

0 голосов
/ 08 мая 2018

Используйте CoordinatorLayout в качестве корневого представления. А также добавьте app: layout_anchorGravity = "bottom | right | end (укажите, как вам нужно) " в FloatingActionButton

0 голосов
/ 08 мая 2018

Попробуйте это

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_gravity="center"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:orientation="horizontal">

                <ImageView
                    android:id="@+id/imgInfo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="5dp"
                    android:src="@drawable/ic_message" />

                <ImageView
                    android:id="@+id/imgLogout"
                    android:layout_width="wrap_content"
                    android:layout_height="20dp"
                    android:layout_marginStart="290dp"
                    android:src="@drawable/ic_message" />

            </LinearLayout>

            <ImageView
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="center_horizontal|center_vertical"
                android:layout_marginTop="10dp"
                android:src="@drawable/kid_goku" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:orientation="horizontal"
                android:paddingStart="120dp">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="40dp"
                    android:layout_gravity="center_horizontal|center_vertical"
                    android:src="@drawable/kid_goku" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:paddingStart="20dp"
                    android:text="name"
                    android:textColor="@color/white"
                    android:textSize="20sp"
                    android:textStyle="bold" />

            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:id="@+id/machineLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white"
            android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="vertical">

            </android.support.v7.widget.RecyclerView>


        </LinearLayout>
    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/search"
        android:layout_width="46dp"
        android:layout_height="wrap_content"
        android:layout_above="@+id/addNew"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@drawable/ic_message" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/addNew"
        android:layout_width="46dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:srcCompat="@drawable/ic_message" />
</RelativeLayout>

OUTPUT

enter image description here

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