0

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.

Umair
  • 6,366
  • 15
  • 42
  • 50
Coder7711
  • 61
  • 1
  • 7

2 Answers2

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