I have a framelayout inside a relative layout and i want to move frame layout a bit to the left and top as a whole. I have been using setLeft() and setTop() method. It is stretching the view but still it is okay for my purpose. My problem is I want the original unstretched frame layout back when I want it. But setting setRight() and putting the same parameter doesn't seem to work. Please help.
how to set left and top margin to a frame layout programmatically?
680 Views Asked by Coder7711 At
2
There are 2 best solutions below
0
On
You can't set Margin to your view like set padding. You need a Layout params for your frame layout then set margin to layout param.
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
layoutParams.setMargins(5, 5, 5, 5);
frameLayout.setLayoutParams(layoutParams);
You can use setMargin to your framelayout