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.
Asked
Active
Viewed 448 times
0
-
is your framelayout to your parent view? – Murat Çakır Feb 25 '20 at 14:39
-
Relative Layout is the parent view of framelayout. – Coder7711 Feb 25 '20 at 14:57
2 Answers
0
You can use setMargin to your framelayout
val par = framelayout?.layoutParams as FrameLayout.LayoutParams
par.rightMargin = 10
par.leftMargin = 30

Murat Çakır
- 150
- 1
- 14
0
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);

Mohanraj
- 296
- 2
- 13