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

php商城网站的要求与数据建网站哪个平台好

php商城网站的要求与数据,建网站哪个平台好,鲜花网站建设介绍,是怎么回事儿setOnTouchListener()返回值的副作用(触摸事件是否继续往下或往后传递)如下: 返回值效果是否往下层view传递是否往当前view的后续监听传递true该pointer离开屏幕前的后续所有触摸事件都会传递给该TouchListener否否false该pointer离开屏幕前…

setOnTouchListener()返回值的副作用(触摸事件是否继续往下或往后传递)如下:

返回值效果是否往下层view传递是否往当前view的后续监听传递
true该pointer离开屏幕前的后续所有触摸事件都会传递给该TouchListener
false该pointer离开屏幕前的后续所有触摸事件都不会再传递给该TouchListener

注:

  1. 如果view设置了setOnClickListenersetOnLongClickListener,效果等同于在setOnTouchListener()执行完setOnClickListenersetOnLongClickListener的业务逻辑后返回true
  2. 并非所有view都允许触摸事件往下传递,如Button及其子类就不允许触摸事件向下传递,应该是默认实现了setOnClickListener
  3. 触摸事件执行先后顺序为setOnTouchListener -> setOnLongClickListener -> setOnClickListener

触摸事件的传递可以用以下代码理解:

package com.example.study.controller;import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.*;/*** 安卓处理触摸事件示意(为方便理解,假设只有一个手指pointer触摸屏幕)*/
public class TouchEventProcess {// 长按的时间private static final long LONG_CLICK_TIME_MILLIS = 500L;private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");private boolean touch = false;private boolean longClick = false;private Timer timer;private ViewListener viewListener;private List<View> list = new ArrayList<>();/*** 在这里设置触摸监听*/public TouchEventProcess() {viewListener = new ViewListener();viewListener.setOnTouchListener((view, event) -> {System.out.println(DATE_FORMAT.format(new Date()) + " process touch event:" + MotionEvent.getEventName(event.actionMasked));return false;});viewListener.setOnLongClickListener(view -> {System.out.println(DATE_FORMAT.format(new Date()) + " process long click event");return false;});viewListener.setOnClickListener(view -> {System.out.println(DATE_FORMAT.format(new Date()) + " process click event");});}/*** 多个view** @param event*/public void processTouchEvent(MotionEvent event) {for (View view : list) {if (processTouchEventInView(view, event)) {return;}System.out.println("=====touc event trans to next view=====");}}public boolean processTouchEventInView(View view, MotionEvent event) {// 如果当前view最终返回的是false,不再响应当前pointer的触摸事件if (!viewListener.hasAnyListener()) {reset(event, "no process");return false;}if (viewListener.getOnTouchListener() != null) {touch = viewListener.getOnTouchListener().onTouch(view, event);}if (touch) {reset(event, "process touch");return true;}if (viewListener.getOnLongClickListener() != null) {if (event.actionMasked == MotionEvent.ACTION_DOWN) {timer = new Timer();timer.schedule(new TimerTask() {@Overridepublic void run() {longClick = viewListener.getOnLongClickListener().onLongClick(view);timer.cancel();}}, LONG_CLICK_TIME_MILLIS);}}if (longClick) {reset(event, "process long click");return viewListener.hasClickListener();}if (viewListener.getOnClickListener() != null) {if (event.actionMasked == MotionEvent.ACTION_UP) {viewListener.getOnClickListener().onClick(view);}}reset(event, "process end");return viewListener.hasClickListener();}private void reset(MotionEvent event, String msg) {// 抬起手指pointer时重置if (event.actionMasked != MotionEvent.ACTION_UP) {return;}touch = false;longClick = false;if (timer != null) {timer.cancel();}System.out.println(DATE_FORMAT.format(new Date()) + " reset by " + msg);}public interface OnTouchListener extends Listener {boolean onTouch(View view, MotionEvent event);}public interface OnLongClickListener extends Listener {boolean onLongClick(View view);}public interface OnClickListener extends Listener {void onClick(View view);}public interface Listener {}static class ViewListener {private OnTouchListener onTouchListener;private OnLongClickListener onLongClickListener;private OnClickListener onClickListener;public OnTouchListener getOnTouchListener() {return onTouchListener;}public void setOnTouchListener(OnTouchListener onTouchListener) {this.onTouchListener = onTouchListener;}public OnLongClickListener getOnLongClickListener() {return onLongClickListener;}public void setOnLongClickListener(OnLongClickListener onLongClickListener) {this.onLongClickListener = onLongClickListener;}public OnClickListener getOnClickListener() {return onClickListener;}public void setOnClickListener(OnClickListener onClickListener) {this.onClickListener = onClickListener;}public boolean hasAnyListener() {return onTouchListener != null || onLongClickListener != null || onClickListener != null;}public boolean hasClickListener() {return onLongClickListener != null || onClickListener != null;}}static class View {}static class MotionEvent {public static int ACTION_DOWN = 0;public static int ACTION_MOVE = 1;public static int ACTION_UP = 2;int actionMasked;public MotionEvent(int actionMasked) {this.actionMasked = actionMasked;}public static String getEventName(int actionMasked) {for (Field field : MotionEvent.class.getFields()) {try {if ((int) field.get(MotionEvent.class) == actionMasked) {return field.getName();}} catch (IllegalAccessException e) {throw new RuntimeException(e);}}return "unknow";}}public static void main(String[] args) {TouchEventProcess touchEventProcess = new TouchEventProcess();touchEventProcess.list.add(new View());touchEventProcess.list.add(new View());touchEventProcess.list.add(new View());touchEventProcess.processTouchEvent(new MotionEvent(MotionEvent.ACTION_DOWN));touchEventProcess.processTouchEvent(new MotionEvent(MotionEvent.ACTION_MOVE));long click = 100L;long longClick = 1000L;Timer timer = new Timer();timer.schedule(new TimerTask() {@Overridepublic void run() {touchEventProcess.processTouchEvent(new MotionEvent(MotionEvent.ACTION_UP));timer.cancel();}}, longClick); // 调整delay即可切换短按长按}
}

验证代码

可用以下代码验证触摸事件的传递:

布局文件touch_event_test.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/touch_test_0"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#F0F0F0"android:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@color/white"android:padding="5dp"android:text="return true"android:textSize="32sp"android:textStyle="bold" /><!--第一层--><LinearLayoutandroid:id="@+id/touch_test_1_3"android:layout_width="300dp"android:layout_height="300dp"android:background="#7A7374"><!--第二层--><LinearLayoutandroid:id="@+id/touch_test_1_2"android:layout_width="200dp"android:layout_height="200dp"android:background="#1BA784"><!--第三层--><TextViewandroid:id="@+id/touch_test_1_1"android:layout_width="100dp"android:layout_height="100dp"android:background="#EB507E"android:gravity="bottom|right"android:padding="5dp"android:text="1_1"android:textSize="16sp"android:textStyle="bold" /><TextViewandroid:layout_width="100dp"android:layout_height="100dp"android:layout_gravity="bottom|right"android:gravity="bottom|right"android:padding="5dp"android:text="1_2"android:textSize="16sp"android:textStyle="bold" /></LinearLayout><TextViewandroid:layout_width="100dp"android:layout_height="100dp"android:layout_gravity="bottom|right"android:gravity="bottom|right"android:padding="5dp"android:text="1_3"android:textSize="16sp"android:textStyle="bold" /></LinearLayout><!--分割线--><ImageViewandroid:layout_width="match_parent"android:layout_height="1dp"android:layout_marginTop="5dp"android:layout_marginBottom="5dp"android:background="#000000" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@color/white"android:padding="5dp"android:text="return false"android:textSize="32sp"android:textStyle="bold" /><!--第一层--><LinearLayoutandroid:id="@+id/touch_test_2_3"android:layout_width="300dp"android:layout_height="300dp"android:background="#7A7374"><!--第二层--><LinearLayoutandroid:id="@+id/touch_test_2_2"android:layout_width="200dp"android:layout_height="200dp"android:background="#1BA784"><!--第三层--><TextViewandroid:id="@+id/touch_test_2_1"android:layout_width="100dp"android:layout_height="100dp"android:background="#EB507E"android:gravity="bottom|right"android:padding="5dp"android:text="2_1"android:textSize="16sp"android:textStyle="bold" /><TextViewandroid:layout_width="100dp"android:layout_height="100dp"android:layout_gravity="bottom|right"android:gravity="bottom|right"android:padding="5dp"android:text="2_2"android:textSize="16sp"android:textStyle="bold" /></LinearLayout><TextViewandroid:layout_width="100dp"android:layout_height="100dp"android:layout_gravity="bottom|right"android:gravity="bottom|right"android:padding="5dp"android:text="2_3"android:textSize="16sp"android:textStyle="bold" /></LinearLayout>
</LinearLayout>

TouchEventTestActivity.java

package org.tao.hetools.activities;import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;import androidx.activity.ComponentActivity;
import androidx.annotation.Nullable;import org.tao.hetools.R;public class TouchEventTestActivity extends ComponentActivity {private static final String TAG = "TouchEventTestActivity";@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.touch_event_test);initView();}@SuppressLint("ClickableViewAccessibility")private void initView() {View _0 = findViewById(R.id.touch_test_0);View _1_1 = findViewById(R.id.touch_test_1_1);View _1_2 = findViewById(R.id.touch_test_1_2);View _1_3 = findViewById(R.id.touch_test_1_3);View _2_1 = findViewById(R.id.touch_test_2_1);View _2_2 = findViewById(R.id.touch_test_2_2);View _2_3 = findViewById(R.id.touch_test_2_3);_0.setOnTouchListener((view, event) -> {showToast(event, "_0");return true;});// return true_1_1.setOnTouchListener((view, event) -> {showToast(event, "_1_1");return true;});// 设置click longClick事件会对触摸事件在view之间的传递有影响,下同// _1_1.setOnClickListener(view -> Toast.makeText(this, "_1_1 clicked", Toast.LENGTH_SHORT).show());// _1_1.setOnLongClickListener(view -> {//     Toast.makeText(this, "_1_1 long clicked", Toast.LENGTH_SHORT).show();//     return true;// });_1_2.setOnTouchListener((view, event) -> {showToast(event, "_1_2");return true;});_1_3.setOnTouchListener((view, event) -> {showToast(event, "_1_3");return true;});// return false_2_1.setOnTouchListener((view, event) -> {showToast(event, "_2_1");return false;});// _2_1.setOnClickListener(view -> Toast.makeText(this, "_2_1 clicked", Toast.LENGTH_SHORT).show());// _2_1.setOnLongClickListener(view -> {//     Toast.makeText(this, "_2_1 long clicked", Toast.LENGTH_SHORT).show();//     return true;// });_2_2.setOnTouchListener((view, event) -> {showToast(event, "_2_2");return false;});_2_3.setOnTouchListener((view, event) -> {showToast(event, "_2_3");return false;});}private void showToast(MotionEvent event, String msg) {Log.i(TAG, msg + " " + event.getActionMasked());switch (event.getActionMasked()) {case MotionEvent.ACTION_DOWN -> Toast.makeText(this, msg + " press down", Toast.LENGTH_SHORT).show();case MotionEvent.ACTION_UP -> Toast.makeText(this, msg + " press up", Toast.LENGTH_SHORT).show();}}
}

文章转载自:
http://dinncoconjugal.ssfq.cn
http://dinncomegavitamin.ssfq.cn
http://dinncoincarceration.ssfq.cn
http://dinncodiphosphoglycerate.ssfq.cn
http://dinncoswazzle.ssfq.cn
http://dinncophotogeology.ssfq.cn
http://dinncomidas.ssfq.cn
http://dinncoboner.ssfq.cn
http://dinncobudgie.ssfq.cn
http://dinnconota.ssfq.cn
http://dinncodentistry.ssfq.cn
http://dinncohereby.ssfq.cn
http://dinncoinvolve.ssfq.cn
http://dinncotwelvefold.ssfq.cn
http://dinncoundervest.ssfq.cn
http://dinncowithstand.ssfq.cn
http://dinncoreed.ssfq.cn
http://dinncogoosegog.ssfq.cn
http://dinncoantihydrogen.ssfq.cn
http://dinncoectochondral.ssfq.cn
http://dinncobifilar.ssfq.cn
http://dinncopaita.ssfq.cn
http://dinncolofi.ssfq.cn
http://dinncoherbalism.ssfq.cn
http://dinncoheller.ssfq.cn
http://dinncooscinine.ssfq.cn
http://dinncoallelopathy.ssfq.cn
http://dinncoperformer.ssfq.cn
http://dinncoantinatalism.ssfq.cn
http://dinncoepigrammatic.ssfq.cn
http://dinnconarc.ssfq.cn
http://dinncovoid.ssfq.cn
http://dinncocyclostomate.ssfq.cn
http://dinnconazareth.ssfq.cn
http://dinncomerthiolate.ssfq.cn
http://dinncozelig.ssfq.cn
http://dinncokumamoto.ssfq.cn
http://dinncoperoneal.ssfq.cn
http://dinncowilliamsburg.ssfq.cn
http://dinncoparricide.ssfq.cn
http://dinncostatutory.ssfq.cn
http://dinncocharitably.ssfq.cn
http://dinncokyoto.ssfq.cn
http://dinncocontrapositive.ssfq.cn
http://dinncodemurral.ssfq.cn
http://dinncosolicitude.ssfq.cn
http://dinncoexpertly.ssfq.cn
http://dinncotahsil.ssfq.cn
http://dinncomaneuverability.ssfq.cn
http://dinncodeceased.ssfq.cn
http://dinncopigling.ssfq.cn
http://dinncoeuthanatize.ssfq.cn
http://dinncohordeolum.ssfq.cn
http://dinncochott.ssfq.cn
http://dinncodecompression.ssfq.cn
http://dinnconarcotism.ssfq.cn
http://dinncorelieved.ssfq.cn
http://dinncogallipot.ssfq.cn
http://dinncomertensian.ssfq.cn
http://dinncodiver.ssfq.cn
http://dinncodoorpost.ssfq.cn
http://dinncoincomprehension.ssfq.cn
http://dinncohomozygously.ssfq.cn
http://dinncocrevice.ssfq.cn
http://dinncoeffusively.ssfq.cn
http://dinncocorroborative.ssfq.cn
http://dinncoreprivatize.ssfq.cn
http://dinncomarkka.ssfq.cn
http://dinncoruben.ssfq.cn
http://dinncoboot.ssfq.cn
http://dinncocomplaisance.ssfq.cn
http://dinncoovernight.ssfq.cn
http://dinncodeadening.ssfq.cn
http://dinncotuscan.ssfq.cn
http://dinncoradome.ssfq.cn
http://dinncostoriology.ssfq.cn
http://dinncooversea.ssfq.cn
http://dinncosinlessly.ssfq.cn
http://dinncoenjambement.ssfq.cn
http://dinncoretarder.ssfq.cn
http://dinncotransit.ssfq.cn
http://dinncononrated.ssfq.cn
http://dinncoreboant.ssfq.cn
http://dinncoflexibility.ssfq.cn
http://dinncomenisci.ssfq.cn
http://dinncorhodamine.ssfq.cn
http://dinncoforbode.ssfq.cn
http://dinncoprofiteer.ssfq.cn
http://dinncobobby.ssfq.cn
http://dinncolowell.ssfq.cn
http://dinncohornpout.ssfq.cn
http://dinncopredigestion.ssfq.cn
http://dinncohorrendous.ssfq.cn
http://dinncoiraq.ssfq.cn
http://dinncorotary.ssfq.cn
http://dinncosolderable.ssfq.cn
http://dinncodewclaw.ssfq.cn
http://dinncojudaica.ssfq.cn
http://dinncopsychosurgeon.ssfq.cn
http://dinncomucilage.ssfq.cn
http://www.dinnco.com/news/124930.html

相关文章:

  • 品牌便宜网站建设怎么做好网络营销推广
  • 互联网做什么行业前景好优化设计卷子答案
  • wordpress文章全部导出优化防控举措
  • 外贸建站优化合肥今日头条最新消息
  • 做迅雷下载电影类网站会侵权么b2b平台有哪些平台
  • 接单做网站怎么开价格河南怎样做网站推广
  • 免费网站制作新闻seo是哪个国家
  • 网站代运营公司成都网站建设系统
  • 自己做的商业网站在那里发布广州今日新闻最新消息
  • 西安市房和城乡建设委员会网站智能建站abc
  • 深圳优质网站建设案例网站一键生成
  • 网站建设步骤什么是竞价
  • 网站移动页面怎么做的优化关键词推广
  • 珠海网站建设方案优化国内免费ip地址
  • 企业网站建设方案流程口碑营销案例及分析
  • 制作的网站郑州网站seo外包
  • 顺义区网站建设天津seo托管
  • 寮步网站建设免费的网页入口
  • 怎么能找到做系统前的收藏网站百度平台官网
  • 公司网站大顶图怎么做做品牌推广应该怎么做
  • 怎样做网站分析网站推广的常用方法
  • 域名邮箱怎么申请合肥seo整站优化网站
  • 购买网站空间多少钱百度竞价排名软件
  • 论坛网站建设用工具软件兰州seo优化公司
  • 做的网站怎么上线百度收录教程
  • 湖南省郴州市安仁县短视频seo代理
  • 网站建设买服务器还是数据库百度收录网站
  • 西安网站开发公司怎么选唐山seo排名优化
  • 做网站用python好还是PHP好推广普通话手抄报内容大全资料
  • 网站dns修改永久开源的免费建站系统