首页推荐优化

This commit is contained in:
18401019693 2022-08-11 18:06:01 +08:00
parent 01d0def52d
commit ee410650f7
2 changed files with 112 additions and 84 deletions

View File

@ -17,53 +17,15 @@
android:paddingEnd="7dp" android:paddingEnd="7dp"
android:paddingBottom="5dp" /> android:paddingBottom="5dp" />
<RelativeLayout
android:id="@+id/banner_layout2"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerVertical="true"
android:layout_marginStart="23dp"
android:gravity="center"
android:padding="1dp"
android:background="@drawable/bg_white_clip"
android:visibility="visible">
<com.yunbao.common.views.weight.ClipPathCircleImage
android:id="@+id/clip_image2"
android:layout_centerInParent="true"
android:layout_width="24dp"
android:layout_gravity="center"
android:layout_height="24dp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/banner_layout3"
android:layout_width="25dp"
android:layout_height="25dp"
android:gravity="center"
android:padding="1dp"
android:layout_centerVertical="true"
android:layout_marginStart="23dp"
android:background="@drawable/bg_white_clip">
<com.yunbao.common.views.weight.ClipPathCircleImage
android:id="@+id/clip_image3"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerInParent="true"
android:layout_gravity="center" />
</RelativeLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/banner_layout1" android:id="@+id/banner_layout1"
android:layout_width="25dp" android:layout_width="25dp"
android:layout_height="25dp" android:layout_height="25dp"
android:gravity="center"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginStart="10dp" android:layout_marginStart="28dp"
android:padding="1dp"
android:background="@drawable/bg_white_clip" android:background="@drawable/bg_white_clip"
android:gravity="center"
android:padding="1dp"
android:visibility="visible"> android:visibility="visible">
<com.yunbao.common.views.weight.ClipPathCircleImage <com.yunbao.common.views.weight.ClipPathCircleImage
@ -74,6 +36,62 @@
android:layout_gravity="center" /> android:layout_gravity="center" />
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:id="@+id/banner_layout2"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerVertical="true"
android:layout_marginStart="28dp"
android:background="@drawable/bg_white_clip"
android:gravity="center"
android:padding="1dp">
<com.yunbao.common.views.weight.ClipPathCircleImage
android:id="@+id/clip_image2"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerInParent="true"
android:layout_gravity="center" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/banner_layout3"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:background="@drawable/bg_white_clip"
android:gravity="center"
android:padding="1dp"
android:visibility="visible">
<com.yunbao.common.views.weight.ClipPathCircleImage
android:id="@+id/clip_image3"
android:layout_width="29dp"
android:layout_height="29dp"
android:layout_centerInParent="true"
android:layout_gravity="center" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/banner_layout4"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:background="@drawable/bg_white_clip"
android:gravity="center"
android:padding="1dp"
android:visibility="visible">
<com.yunbao.common.views.weight.ClipPathCircleImage
android:id="@+id/clip_image4"
android:layout_width="29dp"
android:layout_height="29dp"
android:layout_centerInParent="true"
android:layout_gravity="center" />
</RelativeLayout>
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"

View File

@ -8,11 +8,10 @@ import android.view.View;
import android.view.animation.AlphaAnimation; import android.view.animation.AlphaAnimation;
import android.view.animation.Animation; import android.view.animation.Animation;
import android.view.animation.AnimationSet; import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation; import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.ViewFlipper;
import com.yunbao.common.R; import com.yunbao.common.R;
import com.yunbao.common.bean.AnchorRecommendItemModel; import com.yunbao.common.bean.AnchorRecommendItemModel;
@ -27,13 +26,11 @@ import java.util.List;
*/ */
public class FloatBannerView extends FrameLayout { public class FloatBannerView extends FrameLayout {
private View rootView; private View rootView;
private LinearLayout rootLayout; private RelativeLayout bannerLayout1, bannerLayout2, bannerLayout3, bannerLayout4;
private ViewFlipper homeBanner; private ClipPathCircleImage clipImage1, clipImage2, clipImage3, clipImage4;
private RelativeLayout bannerLayout1, bannerLayout2, bannerLayout3;
private ClipPathCircleImage clipImage1, clipImage2, clipImage3;
private List<AnchorRecommendItemModel> list = new ArrayList<>(); private List<AnchorRecommendItemModel> list = new ArrayList<>();
//默认定时器时间 //默认定时器时间
private int delayMillis = 1500; private int delayMillis = 1000;
//Handler定时加载下一张的数据 //Handler定时加载下一张的数据
private Handler bannerHandler = new Handler(); private Handler bannerHandler = new Handler();
private int index = 0; private int index = 0;
@ -46,13 +43,14 @@ public class FloatBannerView extends FrameLayout {
public FloatBannerView(Context context, AttributeSet attrs) { public FloatBannerView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
rootView = View.inflate(context, R.layout.view_home_float_banner, this); 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); clipImage3 = rootView.findViewById(R.id.clip_image3);
clipImage2 = rootView.findViewById(R.id.clip_image2); clipImage2 = rootView.findViewById(R.id.clip_image2);
clipImage1 = rootView.findViewById(R.id.clip_image1); clipImage1 = rootView.findViewById(R.id.clip_image1);
bannerLayout1 = rootView.findViewById(R.id.banner_layout1); bannerLayout1 = rootView.findViewById(R.id.banner_layout1);
bannerLayout2 = rootView.findViewById(R.id.banner_layout2); bannerLayout2 = rootView.findViewById(R.id.banner_layout2);
bannerLayout3 = rootView.findViewById(R.id.banner_layout3); 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<AnchorRecommendItemModel> mList) { public void showBanner(List<AnchorRecommendItemModel> mList) {
list.clear();
list.addAll(mList);
release(); 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() { public void release() {
bannerHandler.removeCallbacks(mFlipRunnable); bannerHandler.removeCallbacks(mFlipRunnable);
bannerLayout4.clearAnimation();
bannerLayout2.clearAnimation();
} }
private final Runnable mFlipRunnable = new Runnable() { private final Runnable mFlipRunnable = new Runnable() {
@Override @Override
public void run() { public void run() {
if (index == list.size()) { int next = index + 1;
next = (next >= list.size() ? 0 : next);
if (next == 0) {
index = 0; index = 0;
} }
int next = index + 1;
next = (next == list.size() ? 0 : next); float targetX = bannerLayout2.getX() - bannerLayout3.getX();
Uid = String.valueOf(list.get(next).getUid()); float targetY = bannerLayout2.getY() - bannerLayout3.getY();
bannerLayout3.setVisibility(GONE);
ImgLoader.displayAvatar(getContext(), list.get(next).getAvatar(), clipImage3); ImgLoader.displayAvatar(getContext(), list.get(next).getAvatar(), clipImage3);
ImgLoader.displayAvatar(getContext(), list.get(next).getAvatar(), clipImage2); ImgLoader.displayAvatar(getContext(), list.get(next).getAvatar(), clipImage2);
ImgLoader.displayAvatar(getContext(), list.get(index).getAvatar(), clipImage1); TranslateAnimation animationTranslate = new TranslateAnimation(0, -targetX / 1.2f, 0, -targetY / 1.2f);
TranslateAnimation animationTranslate = new TranslateAnimation(0, -20f, 0, 0.2f); ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 1.2f, 1f, 1.2f);
TranslateAnimation animationTranslate3 = new TranslateAnimation(0, -20f, 0, 0.2f);
AnimationSet animationSet1 = new AnimationSet(true); AnimationSet animationSet1 = new AnimationSet(true);
animationSet1.setFillAfter(true); animationSet1.setFillAfter(true);
animationSet1.setDuration(230); animationSet1.setDuration(500);
animationSet1.addAnimation(animationTranslate); animationSet1.addAnimation(animationTranslate);
AlphaAnimation animationAlpha = new AlphaAnimation(1, 0); animationSet1.addAnimation(scaleAnimation);
AnimationSet animationSet2 = new AnimationSet(true); final int finalNext = next;
animationSet2.setFillAfter(true);
animationSet2.setDuration(210);
animationSet2.addAnimation(animationAlpha);
animationSet2.addAnimation(animationTranslate3);
int finalNext = next;
animationSet1.setAnimationListener(new Animation.AnimationListener() { animationSet1.setAnimationListener(new Animation.AnimationListener() {
@Override @Override
public void onAnimationStart(Animation animation) { public void onAnimationStart(Animation animation) {
int page3 = finalNext + 1; int show = finalNext + 1;
page3 = (page3 == list.size() ? 0 : page3);
ImgLoader.displayAvatar(getContext(), list.get(page3).getAvatar(), clipImage2); ImgLoader.displayAvatar(getContext(), list.get(show >= list.size() ? 0 : show).getAvatar(), clipImage1);
} }
@Override @Override
public void onAnimationEnd(Animation animation) { public void onAnimationEnd(Animation animation) {
bannerLayout3.clearAnimation();
ImgLoader.displayAvatar(getContext(), list.get(finalNext).getAvatar(), clipImage1); bannerLayout3.setVisibility(VISIBLE);
int page3 = finalNext + 1;
page3 = (page3 == list.size() ? 0 : page3);
ImgLoader.displayAvatar(getContext(), list.get(page3).getAvatar(), clipImage3);
bannerLayout1.clearAnimation();
} }
@Override @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() { animationSet2.setAnimationListener(new Animation.AnimationListener() {
@Override @Override
public void onAnimationStart(Animation animation) { public void onAnimationStart(Animation animation) {
@ -142,8 +152,10 @@ public class FloatBannerView extends FrameLayout {
@Override @Override
public void onAnimationEnd(Animation animation) { public void onAnimationEnd(Animation animation) {
ImgLoader.displayAvatar(getContext(), list.get(finalNext).getAvatar(), clipImage4);
index = index + 1;
bannerHandler.postDelayed(mFlipRunnable, delayMillis);
bannerLayout3.clearAnimation();
} }
@Override @Override
@ -151,10 +163,8 @@ public class FloatBannerView extends FrameLayout {
} }
}); });
bannerLayout1.startAnimation(animationSet2); bannerLayout4.startAnimation(animationSet2);
bannerLayout3.startAnimation(animationSet1); bannerLayout2.startAnimation(animationSet1);
index = index + 1;
bannerHandler.postDelayed(mFlipRunnable, delayMillis);
} }
}; };