SwipeRefreshLayout behind ActionBar

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?

Answers


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.


Try this code:

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

I hope its work for you.


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


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">

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


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!


Need Your Help

Nodejs / Express - Launching my app: express.createServer() is deprecated

javascript node.js mongodb express socket.io

I downloaded a node app to test and play around with. I have googled around and found that Express is found to be a little outdated. Can someone help me to fix the implemented code?

MVC tutorial that doesn't rely on a framework?

php model-view-controller sample no-framework

I want to learn MVC "architecture pattern" but I don't want to jump into a framework like Rails or Django just yet. I want to understand the concept first and write some simple code in my currently