I have an ImageView and need to set the indent from below.

I do like this

ivRedPoint = (ImageView) findViewById(R.id.rlRedPoint); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.setMargins(25, 12, 32, 21); ivRedPoint.setLayoutParams(lp); 

Here is the XML

 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" > <ImageView android:id="@+id/rlRedPoint" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/style_red_point" android:gravity="center" android:visibility="invisible" /> </LinearLayout> 

This ImageView does not respond to any indents ...

What am I doing wrong?

  • Change the WRAP_CONTENT value to MATCH_PARENT in LayoutParams, or try to directly indent your ImageView. - Tommy
  • You have LinearLayout without orientation and it doesn’t make much use of android: gravity = "center". It’s hard to imagine how the picture should now appear at all - YuriySPb
  • @Tommy If you specify MATCH, the ImageView is stretched to full screen. What does it mean to ask directly? - Aleksey Timoshchenko
  • @ YuriySPb When in LinearLayout one element it is not sensitive to orientation ... And the android: gravity = "center" has a picture in the middle of this LinearLayout ... - Aleksey Timoshchenko
  • in markup in the sense - Tommy

0