开发者

LinearLayout not wrapping image

I've got an ImageView that I've wrapped in a LinearLayout. The LinearLayout has a background drawable which is basically a border, so the effect is that my image has a border around it.

However no matter what I try, I get a big chunk of empty space underneath my image, which is pushing the lower border of my LinearLayout down. I want the LinearLayout to wrap tightly around the image with no padding (except for the 1sp that I specify)

This is how I've defined the two

  <LinearLayout
   a:orientation="vertical" a:layout_width="wrap_content"
   a:layout_height="wrap_content"
   a:gravity="top"
   a:padding="1sp"
   a:background="@drawable/heading_background">  
   <ImageView a:src="@drawable/photo" 
    a:layout_width="wrap_content"
    a:layout_height="wrap_content"
    a:scaleType="fitStart"/>   
  </LinearLayout>
开发者_运维技巧

Can anyone tell me what I'm doing wrong?

Thanks


I don't know how big your drawable is, but if it's really big* then your imageview tries to size itself to that format (wrap_content), but also is restricted by the actual space it's got. What happens exactly is a bit fuzzy for me, but with pictures that get resized (even when keeping aspect ratio like your fitStart does) I had to add the adjustviewbounds attribute: http://developer.android.com/reference/android/widget/ImageView.html#attr_android:adjustViewBounds

It resizes the ImageView back to the format I'd think it would allready have, but in my case it was needed to get it to actually "wrap" the content....

*And I don't mean enormous, just "big enough so it has to be scaled down a bit)


You will want to set a:adjustViewBounds as true in your ImageView. This ensures that the layout will wrap tightly around the image.


android:adjustViewBounds="true"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜