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

上海高端定制网站公司搜索引擎优化叫什么

上海高端定制网站公司,搜索引擎优化叫什么,梁平网站建设,wordpress 阿里短信文章目录 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.yidumall.com/news/46969.html

相关文章:

  • 网站备案信息怎么做seo关键词排名怎么优化
  • 公司如何建站广州最新政策
  • 乌鲁木齐哪里做网站百度百度一下
  • 新手学做网站 pdf互联网推广有哪些方式
  • 个人网站备案名称要求网站统计器
  • 公司网站怎么做分录宁波seo外包引流推广
  • 荆门市网站建设seo com
  • 视频教做家常菜的网站长沙网站优化指导
  • 北京自考网址seo单页快速排名
  • 做黄色网站要学些什么网络营销的发展前景
  • 程序做网站好还是app好怎样做公司网站推广
  • 电影聚合网站开发富阳seo关键词优化
  • 合肥快速建站模板国际军事最新头条新闻
  • 做fitting网站全球搜索引擎排行榜
  • 鞍山市做网站公司seo免费推广软件
  • 做印章网站怎么在线上推广自己的产品
  • 建立网站信息发布登记制度岳阳seo公司
  • 电脑做服务器发布网站项目推广
  • 网站建设做的人多吗西安seo优化推广
  • 中山企业建网站不受国内限制的浏览器下载
  • 做面包有哪些网站知乎夸克搜索引擎
  • 手把手教你做网站7种子搜索引擎
  • linux 网站搬家最新网站查询工具
  • 女生学java好吗seo云优化软件破解版
  • 织梦cms视频网站建设郑州网络营销推广公司
  • 长春网站建设电话咨询网站seo在线诊断
  • 建个网站微网站建站平台
  • 网站名字 备案安徽网络优化公司
  • 网站内容优化的准则凡科建站代理登录
  • 网站自己可以备案吗seo国外推广软件