简体   繁体   中英

ImageView and TextView of LinearLayout not equal width

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);

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM