1717package dev .enginecrafter77 .skeletonlayoutng ;
1818
1919import android .content .Context ;
20+ import android .os .Handler ;
21+ import android .os .Looper ;
2022import android .util .AttributeSet ;
2123import android .view .View ;
2224import android .widget .FrameLayout ;
4042 */
4143public class SkeletonLayout extends FrameLayout implements Skeleton {
4244 private final SkeletonDrawable skeletonDrawable ;
45+ private final Handler handler ;
4346
4447 public SkeletonLayout (@ NonNull Context context )
4548 {
@@ -49,6 +52,7 @@ public SkeletonLayout(@NonNull Context context)
4952 public SkeletonLayout (@ NonNull Context context , @ Nullable AttributeSet attrs )
5053 {
5154 super (context , attrs );
55+ this .handler = new Handler (Looper .getMainLooper ());
5256 this .skeletonDrawable = new SkeletonDrawable ();
5357 this .getOverlay ().add (this .skeletonDrawable );
5458
@@ -71,14 +75,18 @@ public boolean isActive()
7175 @ Override
7276 public void showSkeleton ()
7377 {
74- ViewGroupChildIterator .asIterable (this ).forEach ((View view ) -> view .setVisibility (View .INVISIBLE ));
75- this .skeletonDrawable .showSkeleton ();
78+ this .handler .post (() -> {
79+ ViewGroupChildIterator .asIterable (this ).forEach ((View view ) -> view .setVisibility (View .INVISIBLE ));
80+ this .skeletonDrawable .showSkeleton ();
81+ });
7682 }
7783
7884 @ Override
7985 public void hideSkeleton ()
8086 {
81- ViewGroupChildIterator .asIterable (this ).forEach ((View view ) -> view .setVisibility (View .VISIBLE ));
82- this .skeletonDrawable .hideSkeleton ();
87+ this .handler .post (() -> {
88+ ViewGroupChildIterator .asIterable (this ).forEach ((View view ) -> view .setVisibility (View .VISIBLE ));
89+ this .skeletonDrawable .hideSkeleton ();
90+ });
8391 }
8492}
0 commit comments