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

前端 未结 3 1954
灰色年华
灰色年华 2020-12-28 13:03

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

相关标签:
3条回答
  • 2020-12-28 13:30
    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 讨论(0)
  • 2020-12-28 13:34

    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.

    0 讨论(0)
  • 2020-12-28 13:35

    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"/>
    
    0 讨论(0)
提交回复
热议问题