xml
<ViewFlipper
android:id="@+id/vf"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/me_fulllines"
android:layout_marginLeft="@dimen/dp_20"
android:layout_marginRight="@dimen/dp_20"
android:layout_marginBottom="@dimen/dp_10"
android:background="@drawable/logistics_bg"
android:inAnimation="@anim/anim_marquee_in"
android:minHeight="@dimen/dp_55"
android:outAnimation="@anim/anim_marquee_out" />
可以在xml设置也可在代码设置
autoStart 是否自动开启轮播,这个方法设置为true的时候在源码中,也可以调用java代码
flipInterval 轮播时间
inAnimation ViewFlipper中子View进入时的动画
outAnimation ViewFlipper中子View离开时的动画
setAutoStart(boolean autoStart)//代码设置 true 自动 false 不滚动
选择器anim_marquee_in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fromYDelta="100%p"
android:toYDelta="0"/>
</set>
选择anim_marquee_out
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="1000"
android:fromYDelta="0"
android:toYDelta="-100%p" />
</set>
activity
@BindView(R.id.vf)//物流滚动条
ViewFlipper vf;
接口成功拿到数据
if (orderCount.isSuccess()) {
//物流滚动
if (orderCount.getData().getExpressList() != null && orderCount.getData().getExpressList().size() > 0) {
if (vf.isFlipping()) {
vf.stopFlipping();
}
vf.removeAllViews();
vf.setVisibility(View.VISIBLE);
for (int i = 0; i < orderCount.getData().getExpressList().size(); i++) {
View inflate = View.inflate(getActivity(), R.layout.vf_scroll_, null);
ImageView tv_banner1 = inflate.findViewById(R.id.vf_img);
TextView vf_head = inflate.findViewById(R.id.vf_content);
TextView vf_date = inflate.findViewById(R.id.vf_date);
TextView vf_head1 = inflate.findViewById(R.id.vf_head);//状态判断
OrderCountBean.ExpressListBean expressListBean = orderCount.getData().getExpressList().get(i);
if (expressListBean.getState()==0){
vf_head1.setText("运输中");
}else if (expressListBean.getState()==1){
vf_head1.setText("已揽收");
}else if (expressListBean.getState()==2){
vf_head1.setText("状态异常");
}else if (expressListBean.getState()==3){
vf_head1.setText("已签收");
}else if (expressListBean.getState()==4){
vf_head1.setText("已退签");
}else if (expressListBean.getState()==5){
vf_head1.setText("派件中");
}else if (expressListBean.getState()==6){
vf_head1.setText("退回中");
}else if (expressListBean.getState()==7){
vf_head1.setText("转投中");
}
Glide.with(mContext)
.load(expressListBean.getSkuPic())
.error(R.mipmap.zw_ic)
.placeholder(R.mipmap.zw_ic)
.apply(new RequestOptions().transform(new CenterCrop(), new RoundedCorners(ArmsUtils.dip2px(mContext, 5))))
.into(tv_banner1);
if (expressListBean.getExpressData().size() != 0) {
for (int j = 0; j < expressListBean.getExpressData().size(); j++) {
vf_head.setText(expressListBean.getExpressData().get(j).getContext());
String ftime = expressListBean.getExpressData().get(j).getFtime();
//字符串截取
String str = ftime.substring(0, 10);
vf_date.setText(str);
}
}
inflate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent7 = new Intent(getActivity(), LogisticsActivity.class);
intent7.putExtra("orderId", expressListBean.getOrderProductId() + "");
intent7.putExtra("orderProductId", expressListBean.getOrderProductId() + "");
startActivity(intent7);
}
});
vf.addView(inflate);
}
vf.setFlipInterval(3000);
vf.startFlipping();
} else {
vf.setVisibility(View.GONE);
}