基本知識(shí)
- android中的坐標(biāo)系
在android中最左上角的頂點(diǎn)是坐標(biāo)原點(diǎn)秉溉,在這個(gè)點(diǎn)向右是x軸的正方向碗誉,這個(gè)點(diǎn)的下方是y軸的正方向∨可以通過getRowX()
和getRowY
獲取坐標(biāo)系中的坐標(biāo)
- 觸摸時(shí)間MoveEvent
- public static final int ACTION_DOWN = 0;//單點(diǎn)觸摸按下
- public static final int ACTION_UP = 0;//單點(diǎn)觸摸離開
- public static final int ACTION_MOVE = 0;//單點(diǎn)觸摸移動(dòng)
- public static final int ACTION_CANCLE = 0;//單點(diǎn)觸摸取消
- public static final int ACTION_POINTER_DOWN = 0;//多點(diǎn)觸摸按下
- public static final int ACTION_POINTER_UP = 0;//多點(diǎn)觸摸離開
- view提供的獲取坐標(biāo)的防范
getTop:獲取是view自身底部的到父控件頂邊的距離铛只。同理getLeft,getRight,getBottom都是相對(duì)于其父控件。
- MoverEvent提供的方法
- getX:獲取點(diǎn)擊事件距離當(dāng)前控件左邊的距離(視圖坐標(biāo))
- getY:獲取點(diǎn)擊事件距離當(dāng)前控件頂邊的距離(視圖坐標(biāo))
- getRowX:獲取點(diǎn)擊事件距離屏幕左邊的距離(絕對(duì)坐標(biāo))
- getRowY:獲取點(diǎn)擊事件距離屏幕頂邊的距離(絕對(duì)坐標(biāo))
實(shí)現(xiàn)滑動(dòng)的七方法
- layout(l,t.r,b)
- offsetLeftAndRight(offsetX), offsetTopAndBottom(offsetY)
- LayoutParams
- scrollTo(移動(dòng)到一個(gè)準(zhǔn)確的目標(biāo))淳玩,scrollBy(移動(dòng)一個(gè)偏移量)
- Scroller 類
scroll類的使用方法
1. 初始化Scroller
- 重寫computeScroll 蜕着,實(shí)現(xiàn)模擬滑動(dòng)
@override
public void computescroll(){
super.computeScroll();
//判斷Scroller是否執(zhí)行完畢汽馋,沒有執(zhí)行完畢返回true
if(mScroller.computeScrollOffset()){
((View)getParent()).scrollTo(
mScroller.getCurrX(),
mScroller.getCurrY());
//通過重繪來不斷調(diào)用computeScroll
invalidate();
}`
- startScroll 開啟模擬過程
- 動(dòng)畫屬性
- ViewDraghelper
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者