0

I've been stuck on this for quite some time now. The problem is that I have a linearlayout consisting of multiple textViews and an imageView. However, the imageview has a smaller width than the textviews. I tried everything i could find, but I couldn't find it. I am able to set the image to the left or right by using gravity, but when i use fill, it just centers and keeps the small width. The only thing i can think of is that the image is downloaded in a different thread. Can the width only be set after the image is downloaded?

    // Download photo
    this.post_body.setPhoto(url);
    // Add imageview to linear layout
    this.ll.addView((View) this.post_body.photo);

    LinearLayout.LayoutParams layoutParams;
    layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.gravity = Gravity.FILL_HORIZONTAL;

    this.post_body.photo.setLayoutParams(layoutParams);
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
user3162649
  • 243
  • 1
  • 2
  • 11

1 Answers1

0

Just try to set width=0 and set weight 1 for all the textview and buttons, imageviews whatever you want.

Just try like this here 1f is weight.

layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f);

Amsheer
  • 7,046
  • 8
  • 47
  • 81