@Override
public Object instantiateItem(ViewGroup container, int position) {
if (position < images.length) {
ImageView imageView = new ImageView(MainActivity.this);
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dip2px(300));
imageView.setLayoutParams(lp);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(images[position]);
container.addView(imageView);
return imageView;
} else {
View hintView = LayoutInflater.from(container.getContext()).inflate(R.layout.more_view, container, false);
slideText = (TextView) hintView.findViewById(R.id.tv);
arrowImage = (ImageView) hintView.findViewById(R.id.iv);
container.addView(hintView);
return hintView;
}
}
public class ViewPagerOnPageChangeListener implements ViewPager.OnPageChangeListener {
int currPosition = 0; // 当前滑动到了哪一页
boolean canJump = false;
boolean canLeft = true;
boolean isObjAnmatitor = true;
boolean isObjAnmatitor2 = false;
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (position == (images.length-1)) {
if (positionOffset > 0.35) {
canJump = true;
if (imageAdapter.arrowImage != null && imageAdapter.slideText != null) {
if (isObjAnmatitor) {
isObjAnmatitor = false;
ObjectAnimator animator = ObjectAnimator.ofFloat(imageAdapter.arrowImage, "rotation", 0f, 180f);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
imageAdapter.slideText.setText("松开跳到详情");
isObjAnmatitor2 = true;
}
});
animator.setDuration(500).start();
}
}
} else if (positionOffset <= 0.35 && positionOffset > 0) {
canJump = false;
if (imageAdapter.arrowImage != null && imageAdapter.slideText != null) {
if (isObjAnmatitor2) {
isObjAnmatitor2 = false;
ObjectAnimator animator = ObjectAnimator.ofFloat(imageAdapter.arrowImage, "rotation", 180f, 360f);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
imageAdapter.slideText.setText("继续滑动跳到详情");
isObjAnmatitor = true;
}
});
animator.setDuration(500).start();
}
}
}
canLeft = false;
} else {
canLeft = true;
}
}
@Override
public void onPageSelected(int position) {
currPosition = position;
}
@Override
public void onPageScrollStateChanged(int state) {
if (currPosition == (images.length-1) && !canLeft) {
if (state == ViewPager.SCROLL_STATE_SETTLING) {
if (canJump) {
Toast.makeText(MainActivity.this, "跳转啦", Toast.LENGTH_SHORT).show();
}
new Handler().post(new Runnable() {
@Override
public void run() {
// 在handler里调用setCurrentItem才有效
viewPager.setCurrentItem(images.length-1);
}
});
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有