Reputation: 445
I have a scrollable RelativeLayout that contain some EditText, ImageView and others View elements...
<ScrollView...
<RelativeLayout
<TextView...
<ImageView...
<Button...
...
</RelativeLayout>
</ScrollView>
So now I want to insert a FAB button inside of it so I can scroll all the layout (EditText, ImageView, etc) but with the FAB that is fixed in bottom|right position of the screen. How can I do this? Thanks in advance.
Upvotes: 1
Views: 3804
Reputation: 4837
Your layout should have such structure:
<android.support.design.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto">
<ScrollView
android:id="@+id/svContent"
.....
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
.....
app:layout_anchor="@id/svContent"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
And note attributes layout_anchor
and layout_anchorGravity
there.
Upvotes: 4
Reputation: 302
Code snippet for FAB
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/fab_margin_bottom"
android:layout_marginRight="@dimen/fab_margin_right"
android:src="@android:drawable/icon" />
This will make the FAB stable at bottom if relative layout height is match parent.
Upvotes: 1