diff --git a/common/src/main/res/layout/view_home_float_banner.xml b/common/src/main/res/layout/view_home_float_banner.xml
index 7002c06fa..018d19021 100644
--- a/common/src/main/res/layout/view_home_float_banner.xml
+++ b/common/src/main/res/layout/view_home_float_banner.xml
@@ -17,53 +17,15 @@
android:paddingEnd="7dp"
android:paddingBottom="5dp" />
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
list = new ArrayList<>();
//默认定时器时间
- private int delayMillis = 1500;
+ private int delayMillis = 1000;
//Handler定时加载下一张的数据
private Handler bannerHandler = new Handler();
private int index = 0;
@@ -46,13 +43,14 @@ public class FloatBannerView extends FrameLayout {
public FloatBannerView(Context context, AttributeSet attrs) {
super(context, attrs);
rootView = View.inflate(context, R.layout.view_home_float_banner, this);
- //banner_layout3
+ clipImage4 = rootView.findViewById(R.id.clip_image4);
clipImage3 = rootView.findViewById(R.id.clip_image3);
clipImage2 = rootView.findViewById(R.id.clip_image2);
clipImage1 = rootView.findViewById(R.id.clip_image1);
bannerLayout1 = rootView.findViewById(R.id.banner_layout1);
bannerLayout2 = rootView.findViewById(R.id.banner_layout2);
bannerLayout3 = rootView.findViewById(R.id.banner_layout3);
+ bannerLayout4 = rootView.findViewById(R.id.banner_layout4);
}
@@ -70,10 +68,21 @@ public class FloatBannerView extends FrameLayout {
* 设置轮播数据
*/
public void showBanner(List mList) {
- list.clear();
- list.addAll(mList);
release();
- bannerHandler.post(mFlipRunnable);
+ post(() -> {
+ if (mList.size() < 3) {
+ setVisibility(GONE);
+ return;
+ }
+ list.clear();
+ list.addAll(mList);
+ ImgLoader.displayAvatar(getContext(), list.get(0).getAvatar(), clipImage3);
+ ImgLoader.displayAvatar(getContext(), list.get(1).getAvatar(), clipImage2);
+ ImgLoader.displayAvatar(getContext(), list.get(2).getAvatar(), clipImage1);
+
+ bannerHandler.post(mFlipRunnable);
+ });
+
}
@@ -82,50 +91,45 @@ public class FloatBannerView extends FrameLayout {
*/
public void release() {
bannerHandler.removeCallbacks(mFlipRunnable);
+ bannerLayout4.clearAnimation();
+ bannerLayout2.clearAnimation();
}
private final Runnable mFlipRunnable = new Runnable() {
@Override
public void run() {
- if (index == list.size()) {
+ int next = index + 1;
+ next = (next >= list.size() ? 0 : next);
+ if (next == 0) {
index = 0;
}
- int next = index + 1;
- next = (next == list.size() ? 0 : next);
- Uid = String.valueOf(list.get(next).getUid());
+
+ float targetX = bannerLayout2.getX() - bannerLayout3.getX();
+ float targetY = bannerLayout2.getY() - bannerLayout3.getY();
+ bannerLayout3.setVisibility(GONE);
ImgLoader.displayAvatar(getContext(), list.get(next).getAvatar(), clipImage3);
ImgLoader.displayAvatar(getContext(), list.get(next).getAvatar(), clipImage2);
- ImgLoader.displayAvatar(getContext(), list.get(index).getAvatar(), clipImage1);
- TranslateAnimation animationTranslate = new TranslateAnimation(0, -20f, 0, 0.2f);
- TranslateAnimation animationTranslate3 = new TranslateAnimation(0, -20f, 0, 0.2f);
+ TranslateAnimation animationTranslate = new TranslateAnimation(0, -targetX / 1.2f, 0, -targetY / 1.2f);
+ ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 1.2f, 1f, 1.2f);
AnimationSet animationSet1 = new AnimationSet(true);
animationSet1.setFillAfter(true);
- animationSet1.setDuration(230);
+ animationSet1.setDuration(500);
animationSet1.addAnimation(animationTranslate);
- AlphaAnimation animationAlpha = new AlphaAnimation(1, 0);
- AnimationSet animationSet2 = new AnimationSet(true);
- animationSet2.setFillAfter(true);
- animationSet2.setDuration(210);
- animationSet2.addAnimation(animationAlpha);
- animationSet2.addAnimation(animationTranslate3);
-
- int finalNext = next;
+ animationSet1.addAnimation(scaleAnimation);
+ final int finalNext = next;
animationSet1.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
- int page3 = finalNext + 1;
- page3 = (page3 == list.size() ? 0 : page3);
- ImgLoader.displayAvatar(getContext(), list.get(page3).getAvatar(), clipImage2);
+ int show = finalNext + 1;
+
+ ImgLoader.displayAvatar(getContext(), list.get(show >= list.size() ? 0 : show).getAvatar(), clipImage1);
}
@Override
public void onAnimationEnd(Animation animation) {
- bannerLayout3.clearAnimation();
- ImgLoader.displayAvatar(getContext(), list.get(finalNext).getAvatar(), clipImage1);
- int page3 = finalNext + 1;
- page3 = (page3 == list.size() ? 0 : page3);
- ImgLoader.displayAvatar(getContext(), list.get(page3).getAvatar(), clipImage3);
- bannerLayout1.clearAnimation();
+
+ bannerLayout3.setVisibility(VISIBLE);
+
}
@Override
@@ -133,7 +137,13 @@ public class FloatBannerView extends FrameLayout {
}
});
-
+ TranslateAnimation animationTranslate2 = new TranslateAnimation(0, -targetX / 1.2f, 0, -targetY / 1.2f);
+ AlphaAnimation animationAlpha = new AlphaAnimation(1, 0);
+ AnimationSet animationSet2 = new AnimationSet(true);
+ animationSet2.setFillAfter(true);
+ animationSet2.setDuration(700);
+ animationSet2.addAnimation(animationTranslate2);
+ animationSet2.addAnimation(animationAlpha);
animationSet2.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
@@ -142,8 +152,10 @@ public class FloatBannerView extends FrameLayout {
@Override
public void onAnimationEnd(Animation animation) {
-
-
+ ImgLoader.displayAvatar(getContext(), list.get(finalNext).getAvatar(), clipImage4);
+ index = index + 1;
+ bannerHandler.postDelayed(mFlipRunnable, delayMillis);
+ bannerLayout3.clearAnimation();
}
@Override
@@ -151,10 +163,8 @@ public class FloatBannerView extends FrameLayout {
}
});
- bannerLayout1.startAnimation(animationSet2);
- bannerLayout3.startAnimation(animationSet1);
- index = index + 1;
- bannerHandler.postDelayed(mFlipRunnable, delayMillis);
+ bannerLayout4.startAnimation(animationSet2);
+ bannerLayout2.startAnimation(animationSet1);
}
};