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

群辉授权wordpress权限搜狗整站优化

群辉授权wordpress权限,搜狗整站优化,好看logo图片,做网络销售哪个网站最靠谱呢文章目录 Android 扩大View的点击区域使用padding属性使用TouchDelegate使用getLocationOnScreen监听 Android 扩大View的点击区域 使用padding属性 通过设置 padding 属性扩大点击区域。 使用&#xff1a; <?xml version"1.0" encoding"utf-8"?&…

文章目录

  • Android 扩大View的点击区域
    • 使用padding属性
    • 使用TouchDelegate
    • 使用getLocationOnScreen监听

Android 扩大View的点击区域

使用padding属性

通过设置 padding 属性扩大点击区域。

使用:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center_horizontal"android:orientation="vertical"><TextViewandroid:id="@+id/text1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="20dp"android:text="hello" /><TextViewandroid:id="@+id/text2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:padding="40dp"android:text="world" /></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 = findViewById<TextView>(R.id.text1)
val text2 = findViewById<TextView>(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 version="1.0" encoding="utf-8"?>
<com.example.xxx.view.ParentTouchView xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:orientation="vertical"tools:context=".clickarea.LocationOnScreenActivity"><TextViewandroid:id="@+id/text1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="hello" /></com.example.xxx.view.ParentTouchView>
http://www.tj-hxxt.cn/news/4221.html

相关文章:

  • 国外网站设计新浪nba最新消息
  • wordpress post攻击荥阳网站优化公司
  • 做网站的公司 经营范围全网网络营销
  • 工作证设计风格seo品牌优化整站优化
  • 深圳软件开发培训农大南路网络营销推广优化
  • 用书籍上的文章做网站SEO微博上如何做网站推广
  • 浦东新区网站建设公司哪家靠谱徐州seo推广
  • 做钓鱼网站的公司链接地址
  • 浙江省城乡住房建设部网站西安网站seo厂家
  • 如何给网站做seosem什么意思
  • 百度网站链接提交入口店铺数据分析主要分析什么
  • 多伦多网站建设多少钱广告资源网
  • aspcms网站栏目调用百度推广广告公司
  • 手机网站建设 苏州网络营销的营销方式是什么
  • 网站搭建排名优化电商网站平台
  • 建设工程168类似的网站百度推广收费标准
  • 海尔网站的建设目标个人推广平台
  • 在58同城做网站怎么样广州网站关键词排名
  • dede网站地图模板下载线上推广的方式有哪些
  • 网站图片的像素外贸建站平台
  • 真甲先生网站建设seoul是啥意思
  • 界面设计的重要性二十条疫情优化措施
  • 网站备案有电话来视频广告联盟平台
  • 农产品网站建设计划书网址如何被快速收录
  • 帮客户做网站挣钱吗四川聚顺成网络科技有限公司
  • 在东莞做网站北京seo排名方法
  • 网站开发多语言老铁外链工具
  • 在线客服服务百度快照优化排名推广怎么做
  • 介绍做ppt高大上图表的网站全自动引流推广软件app
  • 集约化政府门户网站建设的优点网站seo什么意思