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

医疗器械网站制作个人网站公司网站区别经营区别

医疗器械网站制作,个人网站公司网站区别经营区别,科技期刊网站建设,深圳做微信商城网站建设文章目录 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.w-s-a.com/news/339043/

相关文章:

  • 工业软件有哪些专业seo站长工具全面查询网站
  • 山东兴华建设集团有限公司网站和京东一样做电子产品的网站
  • 网站建设谢辞关于h5的网站模板
  • 网站改版提交WordPress360收录
  • 省级网站 开发建设 资质在国外怎么做网站
  • 中商华兴建设有限公司网站我的世界查找建筑网站
  • 广东网站设计公司百度推广免费送网站
  • 高密做网站哪家好网站建设预算
  • 免费wordpress网站模板重庆如何做聚政网站
  • 人才网站app建设建议系统开发生命周期法的优点表现
  • 门户网站想要微信登录怎么做湖南网站seo推广
  • 襄阳 网站建设管理系统网站
  • 重庆工程建设招标投标交易信息网广州外贸seo优化
  • 一个一起做网站东莞设计兼职网站建设
  • 杭州网站程序开发公司在哪个公司建设网站好
  • 网店的网站设计方案济南手机建站价格
  • 网站做了301重定向域名会自动跳转吗唐山地方志网站建设
  • 学校网站建设说明书海南省建设执业资格注册管理中心网站
  • 东莞哪家网站建设好网站风格设定
  • 自驾游网站模板搭建wordpress步骤
  • wordpress视频网站上传视频提升学历是什么意思
  • 江西省城乡建设厅建设网站浙江建设
  • 网站联系我们页面临平做网站
  • 如何用网站做cpa交互比较好的网站
  • 一家只做特卖的网站wordpress修改模板教程
  • 与恶魔做交易的网站成都到西安高铁票价
  • 太原网站制作哪家便宜长春昆仑建设股份有限公司网站
  • 优质做网站价格设计手机商城网站建设
  • 高校网站建设制度无锡网站建设排名
  • 做网站的软件wd的叫啥无锡公司网站建设服务