You already have got some down-votes in your question I see. I suppose those are for your question which is not actually clear and the solution you're trying to achieve is not the proper way of doing so too.
From your code of the layout, I have come to understand that you need an up arrow button which will scroll to the top of the RecyclerView
when clicked on it and you want the button to stay in the bottom of the page you're in. You want your RecyclerView
to scroll as it is and the arrow button to stay where it is. If this is your case, then you need to rethink about the layout and the Activity
flow design. You need to make the RecyclerView
and the arrow button completely disjoint.
So, based on my assumption on your question, you need an Activity
which contains a floating action button and holds a Fragment
. The Fragment
will have the RecyclerView
making the floating action button (for the up arrow) and the RecyclerView
completely disjoint.
So you need to have an Activity
and the layout of the Activity
should look like this.
<RelativeLayout 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">
<RelativeLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/activity_horizontal_margin"
android:src="@drawable/ic_up_arrow"
app:backgroundTint="@color/colorPrimary"
app:borderWidth="0dp"
app:elevation="4dp"
app:fabSize="normal" />
</RelativeLayout>
And the onCreate
function of the Activity
should look like this.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layout);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mFabUpArrow = (FloatingActionButton) findViewById(R.id.fab_up);
mFabUpArrow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
jumpToTopOfTheRecyclerView();
}
});
// Now launch the Fragment from here.
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new RecyclerViewFragment()).commit();
}
Now the RecyclerViewFragment
should have the following layout holding the RecyclerView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/your_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
And I think you already know how to populate your RecyclerView
and do that thing in your Fragment
.
You might be asking how to implement the jumpToTopOfTheRecyclerView()
function in the Activity
. Its simple and you've several option. One approach might be having a BroadcastReceiver
in your Fragment
and sending the broadcast from your Activity
which is not so good approach. You might find something very easy to communicate between your Activity
and your Fragment
. Best of luck.