如何将浮动按钮放在特定位置

时间:2017-08-26 08:48:42

标签: android android-layout android-fragments

click here to view image

如何将浮动按钮放置为图像位置。下面是我的XML代码

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.v7.widget.RecyclerView
    android:id="@+id/rec_summary_recycler_view_inflow"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbarSize="5dp"
    android:scrollbars="vertical"
    android:scrollbarThumbVertical="@drawable/scr"/>


<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:backgroundTint="@color/colorPrimary"
    android:src="@drawable/down_arrow"
    android:layout_margin="25dp"
    app:fabSize="mini"
    android:onClick="Scroll" />

3 个答案:

答案 0 :(得分:0)

尝试在fab中添加此行。根据您的需求改变价值。这条线将设置在屏幕的右下方。

android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="end|bottom"

答案 1 :(得分:0)

使用此隐藏在recyclerview滚动中显示工厂

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener()
{
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy)
    {
        if (dy > 0 ||dy<0 && fab.isShown())
        {
            fab.hide();
        }
    }

@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState)
{
    if (newState == RecyclerView.SCROLL_STATE_IDLE)
    {
        fab.show();
    }

    super.onScrollStateChanged(recyclerView, newState);
}
});

答案 2 :(得分:0)

为您的content_layout.xml(id:layout_content)添加一个id,并在您的fab布局中使用app:layout_anchor =“@ id / layout_content”。

<include layout="@layout/content_order_list"
    android:id="@+id/layout_content"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_anchor="@id/layout_content"
    app:layout_anchorGravity="bottom|end"
    android:layout_marginBottom="90dp"
    android:layout_marginEnd="@dimen/activity_horizontal_margin"
    android:layout_marginRight="@dimen/activity_horizontal_margin"
    app:srcCompat="@android:drawable/ic_dialog_email" />
相关问题