How to put Floating Action Button in the bottom of the screen with Collapsing ToolBar to be always visible
I have fragment with floating action button inside activity with collapsing toolbar. When toolbar is collapsed everything is ok, but when it's expended, FAB is not visible (it's below the screen).
Here is xml of my fragment with FAB:
<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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"
/>
</android.support.design.widget.CoordinatorLayout>


add a comment |
I have fragment with floating action button inside activity with collapsing toolbar. When toolbar is collapsed everything is ok, but when it's expended, FAB is not visible (it's below the screen).
Here is xml of my fragment with FAB:
<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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"
/>
</android.support.design.widget.CoordinatorLayout>


1
you can try removing line app:layout_anchor="@+id/layout"
– ahuja007
Nov 21 '18 at 5:57
It doesn't work. Now FAB is in top-left of the layout
– Jacek
Nov 21 '18 at 6:03
where is the code for toolbar, are your toolbar and fab in different xml?
– Karan Mer
Nov 21 '18 at 6:14
also it would be better if you use recyclerview in place of listview.
– Karan Mer
Nov 21 '18 at 6:14
Yes, i will change listview to recyclerview. Toolbar is in activity's xml, this is fragment's xml
– Jacek
Nov 21 '18 at 6:21
add a comment |
I have fragment with floating action button inside activity with collapsing toolbar. When toolbar is collapsed everything is ok, but when it's expended, FAB is not visible (it's below the screen).
Here is xml of my fragment with FAB:
<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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"
/>
</android.support.design.widget.CoordinatorLayout>


I have fragment with floating action button inside activity with collapsing toolbar. When toolbar is collapsed everything is ok, but when it's expended, FAB is not visible (it's below the screen).
Here is xml of my fragment with FAB:
<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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"
/>
</android.support.design.widget.CoordinatorLayout>




asked Nov 21 '18 at 5:42
JacekJacek
33
33
1
you can try removing line app:layout_anchor="@+id/layout"
– ahuja007
Nov 21 '18 at 5:57
It doesn't work. Now FAB is in top-left of the layout
– Jacek
Nov 21 '18 at 6:03
where is the code for toolbar, are your toolbar and fab in different xml?
– Karan Mer
Nov 21 '18 at 6:14
also it would be better if you use recyclerview in place of listview.
– Karan Mer
Nov 21 '18 at 6:14
Yes, i will change listview to recyclerview. Toolbar is in activity's xml, this is fragment's xml
– Jacek
Nov 21 '18 at 6:21
add a comment |
1
you can try removing line app:layout_anchor="@+id/layout"
– ahuja007
Nov 21 '18 at 5:57
It doesn't work. Now FAB is in top-left of the layout
– Jacek
Nov 21 '18 at 6:03
where is the code for toolbar, are your toolbar and fab in different xml?
– Karan Mer
Nov 21 '18 at 6:14
also it would be better if you use recyclerview in place of listview.
– Karan Mer
Nov 21 '18 at 6:14
Yes, i will change listview to recyclerview. Toolbar is in activity's xml, this is fragment's xml
– Jacek
Nov 21 '18 at 6:21
1
1
you can try removing line app:layout_anchor="@+id/layout"
– ahuja007
Nov 21 '18 at 5:57
you can try removing line app:layout_anchor="@+id/layout"
– ahuja007
Nov 21 '18 at 5:57
It doesn't work. Now FAB is in top-left of the layout
– Jacek
Nov 21 '18 at 6:03
It doesn't work. Now FAB is in top-left of the layout
– Jacek
Nov 21 '18 at 6:03
where is the code for toolbar, are your toolbar and fab in different xml?
– Karan Mer
Nov 21 '18 at 6:14
where is the code for toolbar, are your toolbar and fab in different xml?
– Karan Mer
Nov 21 '18 at 6:14
also it would be better if you use recyclerview in place of listview.
– Karan Mer
Nov 21 '18 at 6:14
also it would be better if you use recyclerview in place of listview.
– Karan Mer
Nov 21 '18 at 6:14
Yes, i will change listview to recyclerview. Toolbar is in activity's xml, this is fragment's xml
– Jacek
Nov 21 '18 at 6:21
Yes, i will change listview to recyclerview. Toolbar is in activity's xml, this is fragment's xml
– Jacek
Nov 21 '18 at 6:21
add a comment |
1 Answer
1
active
oldest
votes
replace
app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"
with
android:layout_gravity="bottom|end"
This should work
No, it doesn't work with collapsing toolbar. I have an idea to put FAB to activity xml. I will try it
– Jacek
Nov 21 '18 at 6:14
Yeah please try
– ahuja007
Nov 21 '18 at 6:36
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405879%2fhow-to-put-floating-action-button-in-the-bottom-of-the-screen-with-collapsing-to%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
replace
app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"
with
android:layout_gravity="bottom|end"
This should work
No, it doesn't work with collapsing toolbar. I have an idea to put FAB to activity xml. I will try it
– Jacek
Nov 21 '18 at 6:14
Yeah please try
– ahuja007
Nov 21 '18 at 6:36
add a comment |
replace
app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"
with
android:layout_gravity="bottom|end"
This should work
No, it doesn't work with collapsing toolbar. I have an idea to put FAB to activity xml. I will try it
– Jacek
Nov 21 '18 at 6:14
Yeah please try
– ahuja007
Nov 21 '18 at 6:36
add a comment |
replace
app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"
with
android:layout_gravity="bottom|end"
This should work
replace
app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"
with
android:layout_gravity="bottom|end"
This should work
answered Nov 21 '18 at 6:09


ahuja007ahuja007
21119
21119
No, it doesn't work with collapsing toolbar. I have an idea to put FAB to activity xml. I will try it
– Jacek
Nov 21 '18 at 6:14
Yeah please try
– ahuja007
Nov 21 '18 at 6:36
add a comment |
No, it doesn't work with collapsing toolbar. I have an idea to put FAB to activity xml. I will try it
– Jacek
Nov 21 '18 at 6:14
Yeah please try
– ahuja007
Nov 21 '18 at 6:36
No, it doesn't work with collapsing toolbar. I have an idea to put FAB to activity xml. I will try it
– Jacek
Nov 21 '18 at 6:14
No, it doesn't work with collapsing toolbar. I have an idea to put FAB to activity xml. I will try it
– Jacek
Nov 21 '18 at 6:14
Yeah please try
– ahuja007
Nov 21 '18 at 6:36
Yeah please try
– ahuja007
Nov 21 '18 at 6:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405879%2fhow-to-put-floating-action-button-in-the-bottom-of-the-screen-with-collapsing-to%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
you can try removing line app:layout_anchor="@+id/layout"
– ahuja007
Nov 21 '18 at 5:57
It doesn't work. Now FAB is in top-left of the layout
– Jacek
Nov 21 '18 at 6:03
where is the code for toolbar, are your toolbar and fab in different xml?
– Karan Mer
Nov 21 '18 at 6:14
also it would be better if you use recyclerview in place of listview.
– Karan Mer
Nov 21 '18 at 6:14
Yes, i will change listview to recyclerview. Toolbar is in activity's xml, this is fragment's xml
– Jacek
Nov 21 '18 at 6:21