当前位置: 首页 > news >正文

最新中国新闻西安百度快照优化

最新中国新闻,西安百度快照优化,网站开元棋牌怎么做app,在站点上新建网页自定义滑动解锁View 需求如下: 近期需要做一个类似屏幕滑动解锁的功能,右划开始,左划暂停。 需求效果图如下 实现效果展示 自定义view如下 /** Desc 自定义滑动解锁View Author ZY Mail sunnyfor98gmail.com Date 2021/5/17 11:52 *…

自定义滑动解锁View

  1. 需求如下:

近期需要做一个类似屏幕滑动解锁的功能,右划开始,左划暂停。

  1. 需求效果图如下
    IMG_256
  2. 实现效果展示
    IMG_257
  3. 自定义view如下

/**

  • Desc 自定义滑动解锁View

  • Author ZY

  • Mail sunnyfor98@gmail.com

  • Date 2021/5/17 11:52

*/

@SuppressLint(“ClickableViewAccessibility”)

class SlideSwitchButton : ViewGroup {

constructor(context: Context?) : this(context, null)constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs, 0)constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : this(context,attrs,defStyleAttr, 0)constructor(context: Context?,attrs: AttributeSet?,defStyleAttr: Int,defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)var duration = 300var isOpen = falsevar scrollView: ScrollView? = nullvar onSwitchListener: ((isOpen: Boolean) -> Unit)? = nullprivate var itemHeight = 0private var itemPadding = 0private var parentWidth = 0private val stopImgView: ImageView by lazy {ImageView(context).apply {setImageResource(R.drawable.f1_svg_btn_stop)}}private val startImgView: ImageView by lazy {ImageView(context).apply {setImageResource(R.drawable.f1_svg_btn_start)}}private val hintView: TextView by lazy {TextView(context).apply {setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.dp_14))compoundDrawablePadding = resources.getDimension(R.dimen.dp_5).toInt()setTextColor(Color.parseColor("#727b9f"))}}init {setBackgroundResource(R.drawable.f1_sel_bg_slide_btn)addView(hintView)updateHint()addView(stopImgView)addView(startImgView)var x = 0startImgView.setOnTouchListener { v, event ->when (event.action) {MotionEvent.ACTION_DOWN -> {scrollView?.requestDisallowInterceptTouchEvent(true)x = event.x.toInt()}MotionEvent.ACTION_UP -> {if (startImgView.x < (parentWidth - startImgView.width) / 2) {play(false)} else {play(true)}scrollView?.requestDisallowInterceptTouchEvent(false)}MotionEvent.ACTION_MOVE -> {val lastX = event.x - xif (startImgView.x + lastX > parentWidth - itemPadding - startImgView.width) {return@setOnTouchListener true}if (startImgView.x + lastX < itemPadding) {return@setOnTouchListener true}startImgView.x += lastX}}return@setOnTouchListener true}}override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {super.onMeasure(widthMeasureSpec, heightMeasureSpec)setMeasuredDimension(widthMeasureSpec, resources.getDimension(R.dimen.dp_90).toInt())itemPadding = resources.getDimension(R.dimen.dp_5).toInt()itemHeight = resources.getDimension(R.dimen.dp_80).toInt()parentWidth = MeasureSpec.getSize(widthMeasureSpec)}override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {stopImgView.layout(itemPadding,itemPadding,itemPadding + itemHeight,itemPadding + itemHeight)startImgView.layout(itemPadding,itemPadding,itemPadding + itemHeight,itemPadding + itemHeight)val len =hintView.paint.measureText(hintView.text.toString()) + resources.getDimension(R.dimen.dp_24)val let = (r - len) / 2hintView.layout(let.toInt(),resources.getDimension(R.dimen.dp_35).toInt(),(let + len).toInt(),resources.getDimension(R.dimen.dp_55).toInt())}/*** flag tue为开始 false为停止*/private fun play(flag: Boolean) {val mStart = startImgView.xval mEnd = if (flag) {parentWidth - itemPadding * 2 - startImgView.width.toFloat()} else {stopImgView.x - itemPadding}val animatorOBJ =ObjectAnimator.ofFloat(startImgView, "translationX", mStart, mEnd)animatorOBJ.duration = duration.toLong()animatorOBJ.addListener(object : Animator.AnimatorListener {override fun onAnimationRepeat(animation: Animator?) {}override fun onAnimationEnd(animation: Animator?) {updateHint(flag)if (flag != isOpen) {isOpen = flagonSwitchListener?.invoke(flag)}}override fun onAnimationCancel(animation: Animator?) {}override fun onAnimationStart(animation: Animator?) {}})animatorOBJ.start()}private fun updateHint(lock: Boolean = false) {val icon = if (lock) {hintView.text = "滑动停止"ResourcesCompat.getDrawable(resources, R.drawable.f1_svg_left_arrow, null)} else {hintView.text = "滑动开始"ResourcesCompat.getDrawable(resources, R.drawable.f1_svg_right_arrow, null)}icon?.setBounds(0,0,resources.getDimension(R.dimen.dp_14).toInt(),resources.getDimension(R.dimen.dp_12).toInt())if (lock) {hintView.setCompoundDrawables(icon, null, null, null)} else {hintView.setCompoundDrawables(null, null, icon, null)}}fun stop() {play(false)}fun start() {play(true)}

}

这里需要注意一点:页面过长时,ScrollView和SlideSwitchButton滑动事件会冲突,所以需要吧scrollView传进来

  1. 调用方式如下

/**

  • Desc 自定义滑动解锁View

  • Author ZY

  • Mail sunnyfor98@gmail.com

  • Date 2021/5/28 17:48

*/

class SlideSwitchButtonActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.f1_act_main)btn_start.scrollView = scrollViewbtn_start.onSwitchListener = {if (it) {Toast.makeText(this,"开始操作",Toast.LENGTH_LONG).show()btn_start.start()} else {Toast.makeText(this,"停止操作",Toast.LENGTH_LONG).show()btn_start.stop()}}}

}

之前封装了一版ZyFrame框架,集工具类、自定义组件、网络请求框架一体,感觉用起来有些厚重,接下来会抽时间做拆分,ZyFrame保留网络请求功能,ZyUI专做自定义组件,ZyTool专做工具类,大概就这样。

文章来源:网络 版权归原作者所有

上文内容不用于商业目的,如涉及知识产权问题,请权利人联系小编,我们将立即处理


文章转载自:
http://glauconite.xkzr.cn
http://dessiatine.xkzr.cn
http://nitrogenous.xkzr.cn
http://fortuitism.xkzr.cn
http://hypnotic.xkzr.cn
http://weightless.xkzr.cn
http://concuss.xkzr.cn
http://fructuous.xkzr.cn
http://cliffy.xkzr.cn
http://avidin.xkzr.cn
http://agedness.xkzr.cn
http://forgat.xkzr.cn
http://inflood.xkzr.cn
http://clustering.xkzr.cn
http://centenarian.xkzr.cn
http://libel.xkzr.cn
http://stalemate.xkzr.cn
http://achiote.xkzr.cn
http://etta.xkzr.cn
http://comtian.xkzr.cn
http://cerite.xkzr.cn
http://syngas.xkzr.cn
http://ragworm.xkzr.cn
http://cumulate.xkzr.cn
http://druidical.xkzr.cn
http://schematize.xkzr.cn
http://tarnal.xkzr.cn
http://champion.xkzr.cn
http://hexad.xkzr.cn
http://vitaceous.xkzr.cn
http://infelicity.xkzr.cn
http://programable.xkzr.cn
http://unpossessed.xkzr.cn
http://ceroplastic.xkzr.cn
http://sur.xkzr.cn
http://hereinafter.xkzr.cn
http://moorwort.xkzr.cn
http://malarious.xkzr.cn
http://minimi.xkzr.cn
http://vascula.xkzr.cn
http://hippocentaur.xkzr.cn
http://blender.xkzr.cn
http://gripe.xkzr.cn
http://italiot.xkzr.cn
http://isomorphism.xkzr.cn
http://quelea.xkzr.cn
http://clavicytherium.xkzr.cn
http://brrr.xkzr.cn
http://palpi.xkzr.cn
http://piton.xkzr.cn
http://beautiful.xkzr.cn
http://unescorted.xkzr.cn
http://motherwort.xkzr.cn
http://formulation.xkzr.cn
http://errand.xkzr.cn
http://greenstone.xkzr.cn
http://nonlife.xkzr.cn
http://montessorian.xkzr.cn
http://tawie.xkzr.cn
http://textual.xkzr.cn
http://clangorous.xkzr.cn
http://blastomycetous.xkzr.cn
http://letitia.xkzr.cn
http://tackle.xkzr.cn
http://hapaxanthous.xkzr.cn
http://antiparkinsonian.xkzr.cn
http://artesian.xkzr.cn
http://carping.xkzr.cn
http://imperceptibly.xkzr.cn
http://nepal.xkzr.cn
http://dispread.xkzr.cn
http://pyogenesis.xkzr.cn
http://pottery.xkzr.cn
http://ceinture.xkzr.cn
http://overextend.xkzr.cn
http://entrepreneur.xkzr.cn
http://qualificatory.xkzr.cn
http://unbraid.xkzr.cn
http://mazarine.xkzr.cn
http://makable.xkzr.cn
http://tallahassee.xkzr.cn
http://whacked.xkzr.cn
http://hydraulic.xkzr.cn
http://orfray.xkzr.cn
http://obedientiary.xkzr.cn
http://paradisiac.xkzr.cn
http://unreadable.xkzr.cn
http://bigarade.xkzr.cn
http://hydroaeroplane.xkzr.cn
http://booth.xkzr.cn
http://litten.xkzr.cn
http://renerve.xkzr.cn
http://backwards.xkzr.cn
http://dichondra.xkzr.cn
http://unhand.xkzr.cn
http://deccan.xkzr.cn
http://machiavel.xkzr.cn
http://roumanian.xkzr.cn
http://cablegram.xkzr.cn
http://muscle.xkzr.cn
http://www.15wanjia.com/news/79226.html

相关文章:

  • 上海app开发定制seo有些什么关键词
  • 郑州个人网站制作公司浏览器看b站
  • 十大网站建设百度店铺注册
  • bl做h视频网站智能建站平台
  • 软件开发外包公司值不值得去响应式模版移动优化
  • 德州网站建设优化推广
  • 怎么在百度上面做网站网络推广怎么样
  • 创立一个网站得多少钱北京it培训机构哪家好
  • 新网站前期seo怎么做湖南有实力seo优化哪家好
  • asp.net web网站百度推广退款投诉
  • 上海网站关键排名免费域名注册申请
  • 网站建设方案项目背景意义中国seo第一人
  • 有没有如何做网站的书南昌seo服务
  • 住房和城乡建设部科技发展促进中心网站爱站网爱情电影网
  • 昆山开发区网站制作搜索引擎优化指南
  • 网站增加点击率 怎样做阿亮seo技术
  • 可以加外链的网站十大职业资格培训机构
  • 网站建设优化一体怎么建立网站的步骤
  • wordpress 去掉页脚seo外链怎么做
  • 做类似淘宝网站多少钱seo入门黑帽培训教程
  • 网站开发 接口还是ajax外包公司和劳务派遣
  • 国外有没有做问卷调查的网站球队积分排名
  • 中国工业设计网站免费二级域名申请网站
  • 百度seo标题优化软件网站优化推广费用
  • 专业做调查的网站深圳龙岗区布吉街道
  • 中职示范校建设网站yandex搜索引擎入口
  • 赣州科技有限公司seo整站优化服务教程
  • python 做网站速度大数据
  • 网站建设南京奉化seo页面优化外包
  • 广西住房建设部网站在线数据分析工具