0

I have been trying with TextView and drawableLeft images. but, drawableLeft tend to stick to left everytime(unless TextView.WRAP_CONTENT) .

I have TextViews arranged in my vertical Layout one below another(everything has a drawableLeft too)

I changed one of the TextView+drawableLeft to RelativeLayout+(TextView and ImageView . Applied gravity to center

I was trying to get the left margin of ImageView ,so that I can apply it to later TextView as padding using setPadding(IMAGE_PADDING,0,0,0)

how can I get the left margin from code . I tried

imageView.getPaddingLeft();

its returning 0;

Am I doing it wrong ? is there a way to get it?

Help and Advises needed

naran z
  • 486
  • 3
  • 13
P-RAD
  • 1,293
  • 2
  • 15
  • 36
  • you are using a drawableLeft property of a textView to stick Somewhere else in TextView ?? can you please clearify exactly what you want. or if possible share your xml code or images of what you want. – Manish Jul 18 '14 at 09:39
  • @Manish I am using 5 TextViews with drawableLeft in it , what I basically wanted is to get Text and image centered for each TextView. – P-RAD Jul 18 '14 at 09:49
  • check my answer and tell me if it did the trick. – Manish Jul 18 '14 at 10:26

1 Answers1

0

Set margin like this :

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(left, top, right, bottom);
imageView.setLayoutParams(lp);

Note : This sets margin size in PIXELS, is not the same as the dpi.

check this link

Community
  • 1
  • 1
Manish
  • 1,259
  • 3
  • 11
  • 20