看有心课堂笔记一

一.背景
最近在温习view自定义这一块的知识,所以把一些学过的东西记录下来
二.相关类
1 Configuration:用来描述设备的配置信息,例如用户的配置信息:locale和scaling等等,比如设备的相关信息:输入模式,屏幕大小,屏幕方向等

Configuration configuration = getResource().getConfiguration();
//判断横竖屏
if(configuration.orientation==Configuration.ORIENTATION_PORTRAIT){
}else{
}

2 ViewConfiguration:提供一些自定义控件用到的标准常量,尺寸大小,滑动距离,敏感度等等

    ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
    //获取touchSlop,系统所能获取到的
    // 获取滑动的最小距离
    int touchSlop = viewConfiguration.getScaledTouchSlop();
    // 获取Fling速度的最小值和最大值
    int minimumVelocity = viewConfiguration.getScaledMinimumFlingVelocity();
    int maxmumVelocity = viewConfiguration.getScaledMaximumFlingVelocity();
    // 判断是否有物理按键
    boolean hasPermanentMenuKey = viewConfiguration.hasPermanentMenuKey();
    // 双击间隔时间,在改时间内是双击,否则为单击
    int doubleTapTimeout = ViewConfiguration.getDoubleTapTimeout();
    // 按住状态转为长按状态需要的时间
    int longPressTimeout = ViewConfiguration.getLongPressTimeout();
    // 重复按键的时间
    int keyRepeatTimeout = ViewConfiguration.getKeyRepeatTimeout();

3 GestureDetector:主要作用是简化Touch操作
public class GestureDetectorActivity extends Activity {
private Context mContext;
private GestureDetector mGestureDetector;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    mGestureDetector = new GestureDetector(mContext,new GestureDetectorImpl());
}

private class GestureDetectorImpl implements GestureDetector.OnGestureListener{

    @Override
    public boolean onDown(MotionEvent motionEvent) {
        // 触摸屏幕按下时候
        return false;
    }

    @Override
    public void onShowPress(MotionEvent motionEvent) {

    }

    @Override
    public boolean onSingleTapUp(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public boolean onScroll(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
        // 滚动
        return false;
    }

    @Override
    public void onLongPress(MotionEvent motionEvent) {

    }

    @Override
    public boolean onFling(MotionEvent motionEvent, MotionEvent motionEvent1, float v, float v1) {
        // 滑动
        return false;
    }
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    return mGestureDetector.onTouchEvent(event);
}

}
4 VelocityTracker:用于跟踪触摸屏事件的速率
public class VelocityTrackerActivity extends Activity {

private VelocityTracker mVelocityTracker;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    startVelocityTracker(null);
    getVelocity();
    stopVelocityTracker();
}

private void startVelocityTracker(MotionEvent motionEvent) {
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(motionEvent);
}

private int getVelocity() {
    // 设置VelocityTracker单位,1000表示1秒时间内运动的像素
    mVelocityTracker.computeCurrentVelocity(1000);
    // 获取在1秒内X方向所滑动像素值
    int xVelocity = (int) mVelocityTracker.getXVelocity();
    return Math.abs(xVelocity);
}

private void stopVelocityTracker() {
    if (mVelocityTracker != null) {
        mVelocityTracker.recycle();
        mVelocityTracker = null;
    }
}

}

5 Scroller

6 ViewDragHelper(帮助实现view拖拽的工具)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值