Search code examples
androidimageandroid-layoutuser-experience

Trying to get an ImageView to scale as the screen gets bigger


I'm currently new to Android development, and I'm was trying to get an image to scale for different screen sizes. I made a drawable-hdpi,-mdpi, and drawable-xdpi. In these folders I placed the image but at different sizes for each screen density ( Ex. for xdpi, I made the image bigger). I placed the imageView in the constraint layout and set the height and weight to wrap_content. I was expecting the image to be the same size as the corresponding drawable, but for higher screen densities it was still super small. Any thoughts? I also read about 9 patch images, but I cant just add a larger image to the higher density drawable folders ?


Solution

  • you should change the scaleType of imageview. if you want to scale image with maintain aspect ratio you should use

    <ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitcenter"/>
    

    u can try another option like centerCrop and fitxy and see the result