1

I'm making something like a dashboard for my app. And everything fine except situation with ImageView size for diffrent device's screen inch.

It looks fine on phones and devices 7" and less

enter image description here

But on devices more than 7" it's looking bad

enter image description here

In all cases I used same size of ImageView - 50dp and I have generate MDPI, HDPI, XHDPI, XXHDPI images

If I will use dimens I will get blured images because MDPI, HDPI, XHDPI, XXHDPI images will be generated only for 50dp, but not for 100dp

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="image_size">100dp</dimen>
</resources>

But seems devices with 7" and more inch needs a little more image size, for example, 100dp.

I can't googling the solution. Is it possible to make images looks bigger on 7"+ tablets while not creating extra code?

Trancer
  • 765
  • 2
  • 8
  • 23
  • Create multiple dimen files for tablet and phone. – Naveen Tamrakar Jun 28 '17 at 12:54
  • You could create values depending on screen size. https://stackoverflow.com/questions/30669523/the-size-of-the-buttons-depending-on-the-screen-resolution – svenvdz Jun 28 '17 at 12:54
  • Naveen Tamrakar, I already tryied this method. If specify in dimen.xml various ImageView sizes it will lost image sharpness, image will look blurry – Trancer Jun 28 '17 at 13:52
  • svenvdz, thanks for reply, but seems your link doesn't regards to this quastion. I want make tile icon bigger on tablet but without blurry effect – Trancer Jun 28 '17 at 13:55
  • I know that I can use dimensions such as `300dp` but how I can make all image sizes for every density? – Trancer Jun 28 '17 at 14:32

2 Answers2

0

It is surprising and very strange that no one could give an answer to this seemingly simple question. Well, accidentally I found a solution and it was just as simple

If you want show different image sizes for tablet and phones just create an dimen for it

for phones we show small image with 50dp

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="image_size">50dp</dimen>
</resources>

for tablet around 10" we show 2x size image with 100dp

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="image_size">100dp</dimen>
</resources>

Then in ImageView tag specify size:

<ImageView
    android:layout_width="@dimen/image_size"
    android:layout_height="@dimen/image_size"
    android:id="@+id/imgViewIcon"/>

And necessarily you must make images for phones for different density from original size 50dp and put them in MDPI, HDPI, XHDPI, XXHDPI folders. For tablet make image with 100dp and also generate for different density, then put it in drawable-wNNNdp-?dpi folders, where NNN - screen width and ? - l, m, h, xh, xxh, xxxh dpi. Exactly folders drawable-wNNNdp-?dpi is the answer

Trancer
  • 765
  • 2
  • 8
  • 23
-1

Don't give fix size to imageview.Give imageview's height and width wrap_content in xml....

<ImageView
android:id="@+id/img"
android:src="@drawable/splash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Vishal Vaishnav
  • 3,346
  • 3
  • 26
  • 57