Consider we have an imageView
object like following:
ImageView imageView ;
textView = (TextView) findViewById(R.id.textView);
How can I move the imageView
object in the favorite locations on the layout with programming and of course without changing the its height and width that I had configured in the relativeLayout
.
For moving around a view inside a layout view, you could use margin layout properties such that margin_left
and margin_top
represent how much space should be at left and top of that view respectively from its original position.
If you would like your layout view does not restrict how its child view to be laid out, you would need FrameLayout
. However some other layout views also would offer margin properties.
For example suppose we would like to move that ImageView
by 2px in X direction. The code below, do this.
RelativeLayout.LayoutParams params = textview.getLayoutParams();
params.marginLeft = 2;
textview.requestLayout();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.