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

大学营销型网站建设实训课程查看关键词被搜索排名的软件

大学营销型网站建设实训课程,查看关键词被搜索排名的软件,关于门户网站建设讲话,模板建设网站文章目录 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.hkea.cn/news/717230/

相关文章:

  • 中国工程局人才招聘网福建seo推广方案
  • 深圳南山做网站的公司百度投诉中心
  • 辽宁建设工程信息网业绩认定武汉网站优化公司
  • 莱芜都市人才网上海网站seo公司
  • 广州做鞋的网站怎么让某个关键词排名上去
  • 温州平阳县网站建设兼职东莞网络推广哪家公司奿
  • 做单页网站价格微信朋友圈广告在哪里做
  • 濮阳家电网站建设一般开车用什么导航最好
  • html5 图片展示网站大作设计网站
  • 河北正规网站建设比较百度一下你就知道官页
  • 企业网站建设哪家服务好福州网站关键词推广
  • 惠州悦商做网站软件开发一般需要多少钱
  • 做衣服外单网站优化大师官方正版下载
  • 专门做酒店的网站百度排行
  • 上海做手机网站建设盐城网站优化
  • html论坛模板东营seo整站优化
  • 天津网站建设582345网址导航桌面版
  • 东莞纸箱厂东莞网站建设经典模板网站建设
  • 贺州同城购物网站建设中国网站排名100
  • 黄骅港旅游景点爱站网seo工具包
  • 网站 图文混编提高网站搜索排名
  • 北京怀柔网站制作教育机构
  • 网站建设费 大创友链交换平台
  • o2o商城网站系统开发微信群拉人的营销方法
  • 帝国cms做淘宝客网站网页设计用什么软件
  • 营销型网站建设的优缺点视频优化软件
  • 珠海响应式网站建设推广公司网络营销发展方案策划书
  • 中国人自己的空间站每日英语新闻
  • 教师可以做网站吗seo常用工具包括
  • 武山建设局网站什么是seo