How to put Floating Action Button in the bottom of the screen with Collapsing ToolBar to be always visible












0















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>









share|improve this question


















  • 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


















0















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>









share|improve this question


















  • 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
















0












0








0








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>









share|improve this question














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>






android android-layout android-collapsingtoolbarlayout






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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














1 Answer
1






active

oldest

votes


















0














replace



app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"


with



android:layout_gravity="bottom|end"


This should work






share|improve this answer
























  • 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











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
});


}
});














draft saved

draft discarded


















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









0














replace



app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"


with



android:layout_gravity="bottom|end"


This should work






share|improve this answer
























  • 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
















0














replace



app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"


with



android:layout_gravity="bottom|end"


This should work






share|improve this answer
























  • 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














0












0








0







replace



app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"


with



android:layout_gravity="bottom|end"


This should work






share|improve this answer













replace



app:layout_anchor="@+id/layout"
app:layout_anchorGravity="bottom|right|end"


with



android:layout_gravity="bottom|end"


This should work







share|improve this answer












share|improve this answer



share|improve this answer










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



















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith