• android 公告 滚动 (跑马灯效果)


    notice_vf 为 ViewFlipper

    xml:
    <ViewFlipper
             android:id="@+id/notice_vf"
             android:layout_width="0dp"
             android:layout_marginStart="16dp"
             android:layout_height="match_parent"
             android:layout_weight="1">
    
    </ViewFlipper>
    

      

    activity:

        private var mCurrPos = -1
        private var mNoticeListData: MutableList<NoticeListInfo>? = ArrayList()
        private var mTimer : Timer? = null
        private var mTimerTask : TimerTask? = null
    
    //开启公告通知滚动
        private fun startNoticeRoll() {
            mNoticeListData!!.add(NoticeListInfo(12345))
            mNoticeListData!!.add(NoticeListInfo(23456))
            mNoticeListData!!.add(NoticeListInfo(34567))
            mTimerTask = object : TimerTask() {
                override fun run() {
                    activity!!.runOnUiThread {
                        noticeMoveToNext()
                    }
                }
            }
    
            mTimer = Timer()
            mTimer!!.schedule(mTimerTask,0,5000)
        }
    
        private fun noticeMoveToNext() {
            setNoticeView(mCurrPos, mCurrPos + 1)
            notice_vf.setInAnimation(context,R.anim.in_bottomtop)
            notice_vf.setOutAnimation(context,R.anim.out_topbottom)
            notice_vf.showNext()
        }
    
        private fun setNoticeView(current: Int, nextNum: Int) {
            var next = nextNum
            val noticeView = layoutInflater.inflate(R.layout.item_notice_roll, null)
            val noticeContent = noticeView.findViewById<TextView>(R.id.tv_notice_content)
            if ((current < next) && (next > (mNoticeListData!!.size - 1))) {
                next = 0
            } else if ((current > next) && (next < 0)) {
                next = mNoticeListData!!.size - 1
            }
            noticeContent.text = mNoticeListData!![next].id.toString()
    
            noticeContent.setOnClickListener {
                //跳转到公告详情页
            }
    
            if (notice_vf.childCount > 1) {
                notice_vf.removeViewAt(0)
            }
            notice_vf.addView(noticeView, notice_vf.childCount)
            mCurrPos = next
        }
    

      

      

      

  • 相关阅读:
    CDM中添加Hive服务时Gateway是什么?
    ClouderaManager中Event Server报No such file or directory
    tail -f 与 tail -F的区别
    Zookeeper Canary
    Spark中hashshuffle与sortshuffle
    Spark streaming的执行流程
    Spark streaming的正确使用。。
    spark优化之并行度
    github 使用
    css 通用兄弟选择器( ~ )
  • 原文地址:https://www.cnblogs.com/IT-lss/p/10108754.html
Copyright © 2020-2023  润新知