一、动态设置组件的位置
其中view是需要改变位置的控件,top是需要设制的位置;
private static void setLayoutX(View view,int top)
{
//克隆view的width、height、margin的值生成margin对象
MarginLayoutParams margin=new MarginLayoutParams(view.getLayoutParams());
//设置新的边距
margin.setMargins(margin.leftMargin+350,top,margin.rightMargin,margin.bottomMargin);
//把新的边距生成layoutParams对象
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(margin);
//设制view的新的位置
view.setLayoutParams(layoutParams);
}
二、动态设置组件的大小和动画
/**
*
* @param view 需要设置的组件
* @param height 需要设置的高度
* @param width 需要设置的宽度
* @param animation 需要设置的动画
*/
private static void setLayoutScale(View view,int height,int width,LayoutAnimationController.AnimationParameters animation)
{
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(view.getLayoutParams());
layoutParams.height=height;
layoutParams.width=width;
layoutParams.layoutAnimationParameters=animation;
view.setLayoutParams(layoutParams);
}