Reputation: 14648
I have an imageview that is like this
<ImageView
android:layout_width = "wrap_content"
android:layout_height="wrap_content"
android:src = "@drawable/myimage"/>
the image file "myimage.png" is in all the 4 drawable folders for different densities. The view looks good on phone. If I display it on tablet (say 10inch) then the image "looks" too small because there is so much space.
I know I can create layout for it for large screen size, but where do I place the image file with the bigger size? This way the image file can be picked based on not only density but also screen size
Thank you
Upvotes: 0
Views: 660
Reputation: 39836
You should use the sw
notation.
For example:
layout/activity_with_photo.xml
layout-sw600dp/activity_with_photo.xml // that's a 7 inch tablet
layout-sw720dp/activity_with_photo.xml // that's a nexus 9 and up
and then the bigger images for those layout
// here a 7 inch tabled with all the densities
layout-mdpi-sw600dp/photo.png
layout-hdpi-sw600dp/photo.png
layout-xdpi-sw600dp/photo.png
layout-xxdpi-sw600dp/photo.png
// here a nexus 9 n up with all densities
layout-mdpi-sw720dp/photo.png
layout-hdpi-sw720dp/photo.png
layout-xdpi-sw270dp/photo.png
layout-xxdpi-sw720dp/photo.png
alternatively, if you're doing appropriate scaling of those resources during runtime, you could add to a no-dpi
folder
layout-nodpi-sw600dp/photo.png
layout-nodpi-sw270dp/photo.png
but, if you're using only one, be aware of this here: Bitmap too large to be uploaded into a texture
Upvotes: 1
Reputation: 1954
a tricky way is set scaleType of imageView to fitcenter and set constant width and height to your imageview. it will scale up your icon to specified width and height
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:scaleType="fitCenter"
android:src="@drawable/my_photo"/>
Upvotes: 0
Reputation: 1866
Screen-size specific resources are denoted by small
, medium
, large
and xlarge
. So you need a drawable-small
and/or layout-small
folder etc.
Source: https://developer.android.com/guide/practices/screens_support.html
EDIT: SCREEN SIZE FOLDERS ARE DEPRECATED since Android 3.2. Please use the density folders
Upvotes: 0
Reputation:
Simple Steps: -
If you are using stock icons. Go to this site https://material.io/icons/ . Select and download the icon with a size of 48dp.
Extract the zip file and select all the folders under android and copy them into the res folder of your project. That's it.
Upvotes: 0