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

门户网站模板源码推广app赚佣金接单平台

门户网站模板源码,推广app赚佣金接单平台,企业模板之家,购物平台软件开发Scroller VelocityTracker VelocityTracker 是一个速度跟踪器,通过用户操作时(通常在 View 的 onTouchEvent 方法中)传进去一系列的 Event,该类就可以计算出用户手指滑动的速度,开发者可以方便地获取这些参数去做其他…

Scroller

在这里插入图片描述

VelocityTracker

VelocityTracker 是一个速度跟踪器,通过用户操作时(通常在 View 的 onTouchEvent 方法中)传进去一系列的 Event,该类就可以计算出用户手指滑动的速度,开发者可以方便地获取这些参数去做其他事情。或者手指滑动超过一定速度并松手,就触发翻页。

CustomViewPager

package com.flannery.androidtools.widgets;import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Scroller;/*** VelocityTracker is a concept commonly used in computer graphics, physics simulations, and user interface frameworks to calculate the velocity of an object or pointer based on its position over time. It's particularly useful for creating responsive and realistic interactions in applications like games or touch-based user interfaces.* In the context of Android development, VelocityTracker refers to a class provided by the Android framework. It's used to track the velocity of motion events, such as touch events, on the screen. This can be useful for implementing various gestures and animations that require knowledge of how quickly a user is moving their finger across the screen.* Here's a basic overview of how VelocityTracker works in Android:* Initialization: To use VelocityTracker, you need to create an instance of it and associate it with a specific motion event, typically the ACTION_MOVE events in the case of touch gestures.* Tracking: As the user interacts with the screen, you feed the VelocityTracker instance with the motion events, which contain the current position of the pointer. The VelocityTracker class calculates the velocity based on the change in position over time.* Velocity Retrieval: After you've collected enough motion events, you can retrieve the calculated velocity using the computeCurrentVelocity(int units) method. The units parameter allows you to specify the desired units for the velocity, such as pixels per second.** https://www.nhooo.com/note/qadf7m.html*/
public class CustomViewPager extends ViewGroup {private static final String TAG = CustomViewPager.class.getSimpleName();private int screenWidth;private int screenHeight;private int lastMoveX = 0;private Scroller scroller; // 滚动计算器private VelocityTracker velocityTracker; // 速度跟踪器private int MAX_VELOCITY = 600;private int curScreen = 0;public CustomViewPager(Context context) {super(context);init(context);}public CustomViewPager(Context context, AttributeSet attrs) {super(context, attrs);init(context);}public CustomViewPager(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);init(context);}private void init(Context context) {scroller = new Scroller(context); // 初始化滚动计算器// 添加三个ViewLinearLayout layout1 = new LinearLayout(context);layout1.setBackgroundColor(Color.RED);addView(layout1);LinearLayout layout2 = new LinearLayout(context);layout2.setBackgroundColor(Color.GREEN);addView(layout2);LinearLayout layout3 = new LinearLayout(context);layout3.setBackgroundColor(Color.BLUE);addView(layout3);}@Overridepublic boolean onTouchEvent(MotionEvent event) {Log.i(TAG, "onTouchEvent: onTouchEvent=" + event);if (velocityTracker == null) {velocityTracker = VelocityTracker.obtain(); // 初始化滚动速度跟踪器}velocityTracker.addMovement(event);int x = (int) event.getX();switch (event.getAction()) {case MotionEvent.ACTION_DOWN:lastMoveX = x; // 记录下按下的点break;case MotionEvent.ACTION_MOVE:int dis = lastMoveX - x; // 移动的偏移量Log.i(TAG, "onTouchEvent: dis=" + dis);scrollBy(dis, 0); // 位置滚动lastMoveX = x;break;case MotionEvent.ACTION_UP:velocityTracker.computeCurrentVelocity(1000); // 计算需要的位置int velocityX = (int) velocityTracker.getXVelocity(); // X轴上的速度if (velocityX > MAX_VELOCITY && curScreen > 0) {jump2Screen(curScreen - 1);} else if (velocityX < -MAX_VELOCITY && curScreen < getChildCount() - 1) {jump2Screen(curScreen + 1);} else {int screen = (getScrollX() + screenWidth / 2) / screenWidth;jump2Screen(screen);}if (velocityTracker != null) {velocityTracker.recycle();velocityTracker = null;}break;}return true;}public void jump2Screen(int screen) {curScreen = screen;if (curScreen < 0) {curScreen = 0;}if (curScreen > getChildCount() - 1) {curScreen = getChildCount() - 1;}int dis = curScreen * screenWidth - getScrollX();scroller.startScroll(getScrollX(), 0, dis, 0); // 开始滚动invalidate();}@Overridepublic void computeScroll() {super.computeScroll();if (scroller.computeScrollOffset()) { // 是否处于偏移量的位置scrollTo(scroller.getCurrX(), 0); // 滚动到指定的位置postInvalidate(); // 继续滚动}}@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {super.onMeasure(widthMeasureSpec, heightMeasureSpec);screenWidth = MeasureSpec.getSize(widthMeasureSpec);screenHeight = MeasureSpec.getSize(heightMeasureSpec);setMeasuredDimension(screenWidth, screenHeight);// 给子View设置大小for (int i = 0; i < getChildCount(); i++) {View view = getChildAt(i);view.measure(screenWidth, screenHeight);}}@Overrideprotected void onLayout(boolean changed, int l, int t, int r, int b) {int leftWidth = 0;// 给子View排班for (int i = 0; i < getChildCount(); i++) {View view = getChildAt(i);view.layout(leftWidth, 0, leftWidth + screenWidth, screenHeight);leftWidth = leftWidth + screenWidth;}}
}

资料

Android scrollTo、scrollBy、以及scroller详解
Android Scroller详解
Android自定义ViewPager实例
Android View 的滚动原理和 Scroller、VelocityTracker 类的使用

在这里插入图片描述

http://www.ds6.com.cn/news/35083.html

相关文章:

  • 北京建设信息网站网络服务平台
  • 寻找做网站的公司seo引擎搜索网址
  • 2017年到2018年建设的网站深圳百度网站排名优化
  • 自己做网站难不难深圳网络营销策划有限公司
  • 做刷机网站赚钱吗百家号查询排名数据查询
  • 手机免制作app软件下载广州seo优化电话
  • 怎么给自己的公司做网站西安seo主管
  • 做网站原型现成的框架seo优化推荐
  • 网站注册域名查询怎么登录百度app
  • 鲜花网站数据库建设sem竞价专员是干什么的
  • 移动网站开发语言游戏优化大师有用吗
  • xcache wordpresssem对seo的影响有哪些
  • 退役军人事务部网站建设推广公司有哪些
  • wordpress 301 ssl怀化网站seo
  • php如何给网站做支付接口2022年关键词排名
  • 做网站都需要什么人团杭州seo排名公司
  • 网站空间怎么回事同城广告发布平台
  • 网站没权重十大洗脑广告
  • wordpress页面自由布局网络推广seo是什么
  • 人流什么时间做 新闻源网站2022年新闻摘抄简短
  • 淘宝客如何建立自己的网站企业网站设计论文
  • 微信开放平台登录自己搜20条优化措施
  • 网站图片设计兼职百度怎么发布短视频
  • 哈尔滨住房建设发展集团网站微信小程序开发
  • 网站数字化建设方案广州seo招聘网
  • 404网站页面进入搜索引擎优化名词解释
  • 国外做任务赚钱的网站惠州seo全网营销
  • 网站建设属于固定资产吗域名信息查询网站
  • wdcp 网站打不开全网引流推广
  • 免费域名网站申请百度推广助手下载