1.layout方法
2.offsetLeftAndRight()与offsetTopAndBottom()方法
3.LayoutParams(前提是要有父布局,根据父布局的类型决定LayoutParams的类型),设置leftMargin和topMargin属性,当然也可以直接使用ViewGroup.MarginLayoutParams
4.scrollTo和scrollBy,前者代表移动到最标点(x,y),后者表示移动的增量(dx,dy),但是这个移动的是view的content
5.Scroller,这个可以实现平滑效果,不像srcoolTo和scrollBy那样突兀,实际上也是使用了scrollTo方法,通过重写computeScroll()方法进行重绘,最后stascroll方法即可
scroller = new Scroller(context);
/** * 重写这个方法是Scroller使用的核心,系统的draw()方法中调用改方法 */ @Override public void computeScroll() { super.computeScroll(); /** * 下面可作为模板 */ //判断Scroller是否执行完毕 if (scroller.computeScrollOffset()) { ((View) getParent()).scrollTo(scroller.getCurrX()//获得当前滑动坐标 , scroller.getCurrY()); //通过重绘来不断调用computeScroll,computeScroll()不会自动调用,只能通过invalidate()方法 //invalidate()-->draw()-->computeScroll() invalidate(); } }
6.属性动画
7.ViewDragHelper,google在support库里面提供的DrawerLayout和SlidingPaneLayout两个布局来实现侧滑,里面就是使用的ViewDragHelper