frameLayout代替AbsoluteLayout通过坐标定位

貌似iteye人越来越少了,算了我还是在这里记录一下吧。

你是我的眼,带我阅读浩瀚的书海·········

..........

假如我定义一个需要定位的imageView
ImageView imageView = new ImageView(this);


在AbsoluteLayout中通过x,y定位很好定位,但是貌似被弃用了
AbsoluteLayout.LayoutParams aLayoutParams = new AbsoluteLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,x,y);

imageView.setLayoutParams(aLayoutParams);

上面是在AbsoluteLayout中通过x,y定位。


那么在FrameLayout中如何通过x,y定位呢。看看吧
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

layoutParams.gravity = Gravity.LEFT|Gravity.TOP;

layoutParams.leftMargin = x;

layoutParams.topMargin = y;

imageView.setLayoutParams(layoutParams);

哈哈,看起来和AbsoluteLayout效果差不多哦。这个方法貌似网上说的人比较少额。

你可能感兴趣的:(AbsoluteLayout,LayoutParams)