SwipeRefreshLayout behind ActionBar

匿名 (未验证) 提交于 2019-12-03 01:15:01

问题:

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?

回答1:

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.



回答2:

Try this code:

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

I hope its work for you.



回答3:

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



回答4:

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



回答5:

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


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!



回答6:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!