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

东莞网站建设 烤活鱼ps 做ui比较好的网站

东莞网站建设 烤活鱼,ps 做ui比较好的网站,php网站开发目录,网站被百度降权文章目录 Android 扩大View的点击区域使用padding属性使用TouchDelegate使用getLocationOnScreen监听 Android 扩大View的点击区域 使用padding属性 通过设置 padding 属性扩大点击区域。 使用#xff1a; ?xml version1.0 encodingutf-8? ?xml version1.0 encodingutf-8? LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:gravitycenter_horizontalandroid:orientationverticalTextViewandroid:idid/text1android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:padding20dpandroid:texthello /TextViewandroid:idid/text2android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:padding40dpandroid:textworld //LinearLayout使用TouchDelegate TouchDelegate 类是 Android 中的一个辅助类可以用于扩展 View 的触摸区域如小按钮。 目标View必须有父 View。给多个 View 扩大点击区域时不能是同一个父 View从 View 类的源码中可知设置 setTouchDelegate 时会覆盖之前的。 扩展类 fun View.expandTouchView(expandSize: Int 15.dp) {val parentView parent as? ViewparentView?.post {val rect Rect()getHitRect(rect)Log.e(TAG, rect $rect)rect.left - expandSizerect.top - expandSizerect.right expandSizerect.bottom expandSizeLog.e(TAG, expandRect $rect)parentView.touchDelegate TouchDelegate(rect, this)} }使用 val text1 findViewByIdTextView(R.id.text1) val text2 findViewByIdTextView(R.id.text2)text1.run {expandTouchView()setOnClickListener {ToastUtils.show((it as TextView).text.toString())} }text2.run {expandTouchView(40.dp)setOnClickListener {ToastUtils.show((it as TextView).text.toString())} }使用getLocationOnScreen监听 使用 getLocationOnScreen() 可以获取目标 View 在屏幕中的坐标。RectF 是一个用于表示浮点坐标的矩形区域的类可以用于设置扩大区域。通过监听 onTouchEvent() 触摸方法获取触摸的坐标然后判断是否在扩大区域内。 自定义View class ParentTouchView JvmOverloads constructor(context: Context, attrs: AttributeSet? null, defStyleAttr: Int 0 ) : LinearLayout(context, attrs, defStyleAttr) {private lateinit var text1: TextViewoverride fun onFinishInflate() {super.onFinishInflate()if (childCount 0) {text1 findViewById(R.id.text1)text1.setOnClickListener {ToastUtils.show(text1.text.toString())}}}override fun onTouchEvent(event: MotionEvent?): Boolean {event?.let { e -if (e.action MotionEvent.ACTION_DOWN) {if (isExpandView(text1, e.rawX, e.rawY, 100.dp)) {text1.performClick()}}}return super.onTouchEvent(event)}/*** 是否在View的扩大区域** param targetView 目标View* param touchX 点击的位置* param touchY 点击的位置* param expandSize 扩大区域的大小* return*/private fun isExpandView(targetView: View,touchX: Float,touchY: Float,expandSize: Int 15.dp): Boolean {// 获取目标View的Rectval rect RectF()val location IntArray(2)// 获取目标View的坐标targetView.getLocationOnScreen(location)val childX location[0].toFloat()val childY location[1].toFloat()rect.set(childX,childY,childX targetView.width,childY targetView.height)// 设置扩大区域后的Rectrect.apply {left - expandSizetop - expandSizeright expandSizebottom expandSize}// 判断是否在扩大区域内return rect.contains(touchX, touchY)} }使用 ?xml version1.0 encodingutf-8? com.example.xxx.view.ParentTouchView xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:gravitycenterandroid:orientationverticaltools:context.clickarea.LocationOnScreenActivityTextViewandroid:idid/text1android:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:texthello //com.example.xxx.view.ParentTouchView
http://www.hkea.cn/news/14587059/

相关文章:

  • 分类信息网站营销wordpress 域帐户
  • 做网站是干什么用的越秀企业网站建设
  • 安徽海绵城市建设协会网站公共服务标准化的意义
  • 网站管理助手 二级域名建设局网站施工合同范本
  • 旺道网站排名优化网站建设找刘贺稳营销专家
  • 祭祖网站怎么做wordpress 管理员
  • 免费无版权图片网站风险地区查询最新
  • 推广电影链接赚佣金seo线上培训多少钱
  • 做网站电脑开一天用多少钱wordpress 标签中文
  • 学校网站建设与管理办法安康 住房城乡建设部网站
  • 做网站推广托管费用金乡县住房与城乡建设局网站
  • 长尾词挖掘工具爱站网给手机开发网站
  • 如何做正规电影网站求职简历模板2021
  • 申请建设部门网站的报告简单网页制作过程
  • wordpress api文档宁波seo关键词排名优化
  • 电梯网站建设网站开发的发展
  • 成都网站商城建设百度店铺
  • 商丘高端网站建设做公司的宣传网站需要注意什么
  • 各大门户网站自动建站网站源码
  • 设计网站做的工作步骤是php网站助手
  • 互联网金融网站设计郑州百姓网征婚交友
  • 淘宝怎么才能发布网站建设wordpress 插件 页面
  • 网站改版需要注意哪些seo问题微信公众号 视频网站开发
  • 城阳做网站找哪家好store软件下载
  • 网站seo优化网站我想找一个电销外包团队
  • 网站建设沈阳公司哪家好做外贸要有英文网站吗
  • h5响应式集团网站推荐营销型网站设计流程
  • 毕业设计餐饮网站建设企业logo设计说明
  • 久治县网站建设公司游戏制作公司排名
  • 3g 手机网站wordpress外观自定义