0

emphasized textenter image description here

If I keep 16dp as margin all around 4 sides,why 16 dp length or width is different from left and top?

In the second image,as you can see I have set height as wrap_content and margin is 0 from top too.But still it is applying space from top.So,why it is doing that?What if I add some margin from top?

rahul
  • 31
  • 5
  • Did you mean in your image show different distance from let and top? And you already added 16dp margin 4 sides so wh it is not the same 4 sides? If it is yes. Your image are bounded with wrap content width and height so it takes default width and height from center – Tariqul Islam Feb 27 '20 at 10:20

1 Answers1

0

Because you have to set the android:layout_width and android:layout_height to match_constraint or the special 0dp value inside the layout.xml file. Otherwise looks like you're using wrap_content so it's respecting the constraints by adapting the view to its size.

Some random IT boy
  • 7,569
  • 2
  • 21
  • 47
  • If the question is: why is it still vertically centered it is because the bottom of the image view it is still constrained to the bottom of the parent. If you remove that constraint it should go to the top with the specified margin. – Some random IT boy Feb 27 '20 at 11:08
  • But,I havent applied any margin.It is set to zero on both top and bottom.So,why it is applying space then.It should not because margin is set to zero on top and bottom. – rahul Feb 27 '20 at 11:15
  • Right. Because there is a top constraint that says: stick to the top (image top to parent top) and there's another one that says stick to the bottom (image bottom to parent bottom) so it "balances" and it stays in the middle. If you want it to stay on top you should remove the bottom constraint that attaches the image view to the parent bottom – Some random IT boy Feb 27 '20 at 11:17
  • So,that means it ignores margins?Even if I apply any value to top or bottom,it will stay center? – rahul Feb 27 '20 at 11:28
  • the margins are calculated and they are there in the view hierarchy but the visual effect that is centered. if you would like to move the image _a little bit up_ you can play with the ConstraintLayout bias. Which is the sliders that initially have a 50 inside them. – Some random IT boy Feb 27 '20 at 11:31
  • https://stackoverflow.com/questions/62378079/query-in-image-size-in-android-studio – rahul Jun 15 '20 at 08:06
  • https://stackoverflow.com/questions/63374219/activity-has-leaked-window-that-was-originally-added-logcat-error – rahul Aug 12 '20 at 11:51