Skip to content

Commit 0fb78ce

Browse files
committed
add Gloading.cover(view) to support RelativeLayout and ConstraintLayout usage
1 parent 150b6dc commit 0fb78ce

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Diff for: gloading/src/main/java/com/billy/android/loading/Gloading.java

+27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.util.SparseArray;
88
import android.view.View;
99
import android.view.ViewGroup;
10+
import android.view.ViewParent;
1011
import android.widget.FrameLayout;
1112
import android.widget.FrameLayout.LayoutParams;
1213

@@ -15,12 +16,21 @@
1516
* usage:<br>
1617
* //if set true, logs will print into logcat<br>
1718
* Gloading.debug(trueOrFalse);<br>
19+
*
1820
* //init the default loading status view creator ({@link Adapter})<br>
1921
* Gloading.initDefault(adapter);<br>
22+
*
2023
* //wrap an activity. return the holder<br>
2124
* Holder holder = Gloading.getDefault().wrap(activity);<br>
25+
*
2226
* //wrap an activity and set retry task. return the holder<br>
2327
* Holder holder = Gloading.getDefault().wrap(activity).withRetry(retryTask);<br>
28+
*
29+
* //wrap a view and set retry task. return the holder<br>
30+
* Holder holder = Gloading.getDefault().wrap(view).withRetry(retryTask);<br>
31+
*
32+
* //cover a view which relatives to another view within a parent of RelativeLayout or ConstraintLayout parent
33+
* Holder holder = Gloading.getDefault().cover(view).withRetry(retryTask);<br>
2434
* <br>
2535
* holder.showLoading() //show loading status view by holder<br>
2636
* holder.showLoadSuccess() //show load success status view by holder (frequently, hide gloading)<br>
@@ -132,6 +142,23 @@ public Holder wrap(View view) {
132142
return new Holder(mAdapter, view.getContext(), wrapper);
133143
}
134144

145+
/**
146+
* loadingStatusView shows cover the view with the same LayoutParams object
147+
* this method is useful with RelativeLayout and ConstraintLayout
148+
* @param view the view which needs show loading status
149+
* @return Holder
150+
*/
151+
public Holder cover(View view) {
152+
ViewParent parent = view.getParent();
153+
if (parent == null) {
154+
throw new RuntimeException("view has no parent to show gloading as cover!");
155+
}
156+
ViewGroup viewGroup = (ViewGroup) parent;
157+
FrameLayout wrapper = new FrameLayout(view.getContext());
158+
viewGroup.addView(wrapper, view.getLayoutParams());
159+
return new Holder(mAdapter, view.getContext(), wrapper);
160+
}
161+
135162
/**
136163
* Gloading holder<br>
137164
* create by {@link Gloading#wrap(Activity)} or {@link Gloading#wrap(View)}<br>

0 commit comments

Comments
 (0)