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?
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?
In the Material Design version of the appcompat-v7 library (v21.0.0), SwipeRefreshLayout
gets a method to set the Progress View offset.
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.
The method setProgressViewOffset(boolean, int, int) is undefined for the type SwipeRefreshLayout
. Please see my question about this: #26714332 –
Voccola 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">
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!
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
© 2022 - 2024 — McMap. All rights reserved.