滚动广告条one ScrollTextView

public class ScrollTextView extends LinearLayout {
              private ImageView mBannerTV1;
              private TextView mBannerTV2;
             private Handler handler;
             private boolean isShow = false;
             private int startY1, endY1, startY2, endY2;
              private Runnable runnable;
            private List<EarningBean.DatasBean.CustProfitListBean> list;
            private int position = 0;
           private int offsetY = 100;
private boolean hasPostRunnable = false;

public ScrollTextView(Context context) {
    this(context, null);
}

public ScrollTextView(Context context, @Nullable AttributeSet attrs) {
    this(context, attrs, 0);
}

public ScrollTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    View view = LayoutInflater.from(context).inflate(R.layout.widget_scroll_text_layout, this);
    mBannerTV1 = view.findViewById(R.id.tv_banner1);
    mBannerTV2 = view.findViewById(R.id.tv_banner2);

    handler = new Handler();
    runnable = new Runnable() {
        @Override
        public void run() {
            isShow = !isShow;
            if (position == list.size() - 1) {
                position = 0;
            }

            if (isShow) {
                EarningBean.DatasBean.CustProfitListBean custProfitListBean = list.get(position);
                Glide.with(context).load(custProfitListBean.getCust_avatar()).apply(RequestOptions.bitmapTransform(new CircleCrop())).into(mBannerTV1);
                mBannerTV2.setText(custProfitListBean.getContent());
            } else {
                EarningBean.DatasBean.CustProfitListBean custProfitListBean = list.get(position);
                Glide.with(context).load(custProfitListBean.getCust_avatar()).apply(RequestOptions.bitmapTransform(new CircleCrop())).into(mBannerTV1);
                mBannerTV2.setText(custProfitListBean.getContent());
            }
            ObjectAnimator.ofFloat(mBannerTV1, "translationX", startY1, endY1).setDuration(300).start();
            ObjectAnimator.ofFloat(mBannerTV2, "translationY", startY2, endY2).setDuration(300).start();
            position++;
            handler.postDelayed(runnable, 3000);
        }
    };
}

public List<EarningBean.DatasBean.CustProfitListBean> getList() {
    return list;
}

public void setList(List<EarningBean.DatasBean.CustProfitListBean> list) {
    this.list = list;

    //处理最后一条数据切换到第一条数据 太快的问题
    if (list.size() > 1) {
        list.add(list.get(position));
    }
}

public void startScroll() {
    //  mBannerTV1.setText(list.get(0));
    if (list.size() > 1) {
     /*   EarningBean.DatasBean.CustProfitListBean custProfitListBean = list.get(position);
        Glide.with(getContext()).load(custProfitListBean.getCust_avatar()) .apply(RequestOptions.bitmapTransform(new CircleCrop())).into(mBannerTV1);
        mBannerTV2.setText(custProfitListBean.getContent());*/
        if (!hasPostRunnable) {
            hasPostRunnable = true;
            //处理第一次进入 第一条数据切换第二条 太快的问题
            handler.postDelayed(runnable, 1);
        }
    } else {
        //只有一条数据不进行滚动            hasPostRunnable = false;
 //   mBannerTV1.setText(list.get(0));
    }
}
public void stopScroll() {
    handler.removeCallbacks(runnable);
    hasPostRunnable = false;
}
}

引入

                        <com.aizhiyi.widget.ScrollTextView
                        android:id="@+id/gundong"
                        android:layout_width="match_parent"
                       android:layout_height="wrap_content"
                        android:layout_marginTop="@dimen/dp_10"
                        android:orientation="horizontal" />

activity使用

               ProgressDialogUtils.dismissDialog();
            if (earningBean.getCode() == 200 && earningBean.getDatas().getCust_profit_list().size() > 0) {
                gundong.setVisibility(View.VISIBLE);
  List<EarningBean.DatasBean.CustProfitListBean> cust_profit_list = ;
                cust_profit_list.clear();
                          cust_profit_list.addAll(earningBean.getDatas().getCust_profit_list());
                if (cust_profit_list.size() != 0) {
                    gundong.setList(cust_profit_list);
                    gundong.startScroll();
                vf.setVisibility(View.VISIBLE);}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值