Android浮动按钮未设置在固定位置
我在活动中显示2个浮动按钮,但当活动中没有数据显示时,浮动按钮设置在底部。如果活动中显示记录,则浮动按钮显示在记录之后,而不是固定位置 下面是我的活动布局Android浮动按钮未设置在固定位置,android,android-layout,Android,Android Layout,我在活动中显示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-aut
<?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" />
在屏幕截图之后
试试这个
<?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>
输出
将CoordinatorLayout用作根视图。
并添加app:layout_anchorGravity=bottom | right | end在FloatingActionButton中根据需要指定您应该将Floating按钮放在主父布局RelativeLayout中。您已将其放入子布局LinearLayout,其中还包含recyclerview。所以,如果recyclerview添加项目,则按钮将向下移动。我也遇到了同样的问题,当晶圆厂没有固定在它们的位置时,所以我使用了CircleImageView。我更新了我的问题。你能告诉我我在哪里吗wrong@pravinmaske把我的答案复制粘贴到你的layout@pravinmaske将android:layout_alignParentBottom=true从搜索引擎中删除,并在上面添加这个`android:layout_=@+id/addNew它会工作的谢谢@Nilesh Rathod