Android 代码当中动态改变某个控件的位置

不多说,直接上代码:

private ImageView imageView; //小圆圈
private RelativeLayout mRlImg;
mRlImg = (RelativeLayout) view.findViewById(R.id.rl_img);

/**
 * 初始化圆圈
 */
public void initCicleImg() {
    imageView = new ImageView(getActivity());
    imageView.setBackgroundResource(R.mipmap.count_progressicon);
    imageView.setFocusable(false);
    mRlImg.addView(imageView);
}

RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
params.setMargins(880, mMoveLocation + 55, 0, 0);// 通过自定义坐标来放置你的控件
imageView.setLayoutParams(params);

你可能感兴趣的:(Android,自定义控件进阶)