ImageView size for phones and tablets

十年热恋 提交于 2019-12-11 06:46:54

问题


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

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

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?


回答1:


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




回答2:


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"/>


来源:https://stackoverflow.com/questions/44803011/imageview-size-for-phones-and-tablets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!