SwipeRefreshLayout behind ActionBar
Asked Answered
A

6

38

When using a SwipeRefreshLayout in combination with a overlay mode ActionBar, the loading animation will be displayed behind the actionbar, making it almost invisible.

Is there anything I can do to show it on top of the actionbar?

Acicular answered 25/6, 2014 at 16:10 Comment(1)
I have the same issue, can't figure out a way to show the loader in the right positionReceptionist
F
69

In the Material Design version of the appcompat-v7 library (v21.0.0), SwipeRefreshLayout gets a method to set the Progress View offset.

https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html#setProgressViewOffset(boolean,%20int,%20int)

public void setProgressViewOffset (boolean scale, int start, int end)

The refresh indicator starting and resting position is always positioned near the top of the refreshing content. This position is a consistent location, but can be adjusted in either direction based on whether or not there is a toolbar or actionbar present.

Parameters

scale Set to true if there is no view at a higher z-order than where the progress spinner is set to appear.

start The offset in pixels from the top of this view at which the progress spinner should appear.

end The offset in pixels from the top of this view at which the progress spinner should come to rest after a successful swipe gesture.

Fidelity answered 21/10, 2014 at 19:28 Comment(1)
I have imported the new library and it's working fine (I can see the new swiperefreshanimation) but I need to move it down. Using this method I get The method setProgressViewOffset(boolean, int, int) is undefined for the type SwipeRefreshLayout. Please see my question about this: #26714332Voccola
N
20

Try this code:

int top_to_padding=100;
swipe_refresh_layout.setProgressViewOffset(false, 0,top_to_padding);

I hope its work for you.

Nor answered 28/3, 2015 at 9:28 Comment(0)
F
4

the answer of Vijay Rajput works for me, but the problem was only on Kitkat or hight so I included:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { swipeLayout.setProgressViewOffset(false, 0,100); }

Flynn answered 26/4, 2015 at 13:2 Comment(0)
M
2

Instead of setting paddingTop on the SwipeRefreshLayout, setting the layout_marginTop will make the progress bar visible:

<android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="?android:attr/actionBarSize">
Maurya answered 28/8, 2014 at 20:23 Comment(1)
Yes, but the list must be able to scroll under the action bar to make the animation look good (I use an overlay mode Actionbar; the action bar is semi-transparent). The list must be the direct child of SwipeFreshLayout, so this will not work.Acicular
C
1

EDIT

This was the best solution before the v21 of the appcompat-v7 library. If you're using v21 or newer, please check the approved answer. In case you're using appcompat-v7 < 21 API this would still help you.


You can fix this easily by copying the SwipeRefreshLayout (and its dependencies) into your project and change where the progress bar is displayed, adding a top margin.

To make it easy for everyone I released a library with the margin implemented. Take a look at this: https://github.com/Naroh091/SwipeRefreshLayoutOverlay

Hope it helps!

Cheater answered 5/7, 2014 at 18:34 Comment(4)
Too bad this solution involves copying the whole code of the SwipeRefreshLayout class.Acicular
We need someone who works on this at Google create a method for it. Hate having to move away from official code.Bathyal
link is not valid anymore.Amoretto
@NicolasTyler thank you for the warning, I've updated the answer.Cheater
C
1

I have currently come across this when I upgraded my dependency from appcompat 19.1.0 to 21.0.0 and made no code changes.

This is actually a known issue with SwipeRefreshLayout in appcompat 21.0.0.

Look here for a workaround: https://code.google.com/p/android/issues/detail?id=77712

Chronaxie answered 31/10, 2014 at 17:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.