0
点赞
收藏
分享

微信扫一扫

深入解析C++树形关联式容器:map、set及其衍生容器的使用与原理

小典典Rikako 03-17 20:30 阅读 8

46. Android中View几种常见位移方式的区别?

1. offsetLeftAndRight() 和 offsetTopAndBottom() (推荐)
实现的是对view的移动
offsetLeftAndRight(int offset): 水平方向挪动View,offset为正则x轴正向移动,getLeft()和getRight()会变。
offsetTopAndBottom(int offset): 垂直方向挪动View,offset为正则y轴正向移动,getTop()和getBottom会变。


2. scrollBy() 和 scrollTo() (推荐)
对View内容的移动
scrollBy() :位移指定的偏移量
scrollTo() :位置到指定的位置

3. translationX 和 translationY
实现的是对view的移动
相对于left,top,在view的平移过程中,left和top始终等于view初始状态时的值,只是x,y和translationX,translationY会发生改变,
translationX:代表View平移的水平距离;
translationY:代表View平移的垂直距离;


4.更改LayoutParams属性(不推荐)
示例
表示将view向右移动了100px

MarginLayoutParams params = (MarginLayoutParams) mButton.getLayoutParams();
params.leftMargin += 100;
// 请求重新对View进行measure、layout
mButton.requestLayout();

5.使用Scroller来实现平滑滑动
示例(模板代码)
本质依旧是调用了scrollTo()方法

Scroller scroller = new Scroller(mContext);

private void smoothScrol
举报

相关推荐

0 条评论