开发者

How do I make my ImageView a fixed size regardless of the size of the bitmap

So I'm loading images from a web service, but the size of the images are sometimes smaller or bigger than other images and the visualization looks silly when I put them in a ListView in android. I'd like to fix the size of my ImageView so that it only shows a portion of the image if it's larger than a preset amount. I've tried everything I can think of setting the setMaxWidth/setMaxHeight, setting the scale type to centerCrop, using ClipableDrawable wrapping my BitmapDrawable, setting using Drawable.setBounds(). I've tried setting in the XML and programmatically, but neither worked. I'm very surprised setting max width/height didn't do anything. Below is the XML I'm using ImageView definition in my layout file:

    <ImageView android:id="@+id/recipeImage"
           android:maxHeight="64px"
           android:maxWidth="64px"
           android:scaleType="centerCrop"
           android:layout_width="wrap_content"
           android:layout_height="fill_parent"
      开发者_StackOverflow中文版     android:layout_alignParentTop="true"
           android:layout_alignParentBottom="true"
           android:layout_marginRight="6dip"/>

But,nothing has worked.


Just delete the maxHeight and maxWidth attributes and enter your units in layout_width and layout_height appropriately. But do not use the px unit - use dp instead, because these are device-independent.


This will fit the image in the specified height and width, irrespective of image size.

<ImageView
        android:id="@+id/image5"
        android:layout_width="300dp"
        android:layout_height="200dp"
        android:src="@drawable/image_1"
        android:scaleType="fitXY"/>


Get ImageVIews as facebook posts.    
Glide.with(context).load(link)
                    .placeholder(R.drawable.aboutlogo)
                    .fitCenter()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .into(imageView);`

        <ImageView
                    android:id="@+id/img1"
                    android:src="@drawable/ic_menu_camera"
                    android:adjustViewBounds="true"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:scaleType="center"/>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜