Swiperefreshlayout, When Visibility == View.gone, Doesn't Hide Child View
Solution 1:
If you can confirm that this is not caused by your setup, you should report this as a bug, see https://source.android.com/source/report-bugs.html.
As a workaround I recommend to wrap your layout into a FrameLayout
and set the visibility on it instead of the SwipeRefreshLayout
.
Solution 2:
In your xml file provide id to SwipeRefreshLayout and view
<android.support.v4.widget.SwipeRefreshLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/mySwipeRefreshLayout"><Viewandroid:background="#FF0000"android:layout_width="match_parent"android:layout_height="match_parent" /></android.support.v4.widget.SwipeRefreshLayout>
then use id of both in .java file and use their objects.
if(swipeRefreshLayout.isRefreshing()){
view.setVisibility(View.VISIBLE);
}else{
view.setVisibility(View.INVISIBLE);
}
Solution 3:
I feel dumb, but my problem ended up being this: SwipeRefreshLayout doesn't hide while it is animating the refresh logo. You have to setRefreshing(false)
in addition to setVisibility(View.GONE)
. Even after setRefreshing(false)
, there is an exit animation that happens after you use both of these methods.
Here's the solution I used to fix this. It not only handles calling setRefreshing(false)
when you want to hide it, but it also sets the alpha to zero so it hides immediately without having to wait for the refresh animation to wind down.
publicclassHideableSwipeRefreshLayoutextendsSwipeRefreshLayout {
publicHideableSwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@OverridepublicvoidsetVisibility(int visibility) {
if ((visibility == View.INVISIBLE) || (visibility == View.GONE)) {
setAlpha(0);
setRefreshing(false);
} else {
setAlpha(1);
}
super.setVisibility(visibility);
}
}
Post a Comment for "Swiperefreshlayout, When Visibility == View.gone, Doesn't Hide Child View"