简体   繁体   English

手机和平板电脑的ImageView大小

[英]ImageView size for phones and tablets

I'm making something like a dashboard for my app. 我正在为我的应用制作仪表板之类的东西。 And everything fine except situation with ImageView size for diffrent device's screen inch. 一切都很好,除了ImageView大小适合不同设备屏幕英寸的情况。

It looks fine on phones and devices 7" and less 在7英寸及以下的手机和设备上看起来不错

在此处输入图片说明

But on devices more than 7" it's looking bad 但是在超过7英寸的设备上看起来很糟糕

在此处输入图片说明

In all cases I used same size of ImageView - 50dp and I have generate MDPI, HDPI, XHDPI, XXHDPI images 在所有情况下,我都使用相同大小的ImageView-50dp,并且生成了MDPI,HDPI,XHDPI,XXHDPI图像

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 如果我使用调光,则会得到模糊的图像,因为MDPI,HDPI,XHDPI,XXHDPI图像仅针对50dp生成,而不会针对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. 但是似乎7英寸或更大英寸的设备需要更大的图像尺寸,例如100dp。

I can't googling the solution. 我无法搜索解决方案。 Is it possible to make images looks bigger on 7"+ tablets while not creating extra code? 是否可以使图像在7英寸以上的平板电脑上看起来更大,而无需创建额外的代码?

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 如果你想显示平板电脑不同的图像大小和电话只是创建一个dimen

for phones we show small image with 50dp 对于手机,我们以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 对于10英寸左右的平板电脑,我们以100dp显示2倍尺寸的图像

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

Then in ImageView tag specify size: 然后在ImageView标记中指定大小:

<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. 而且,您必须为手机制作的图像具有与原始大小50dp不同的密度,并将其放入MDPI,HDPI,XHDPI,XXHDPI文件夹中。 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 ? 对于平板电脑,以100dp制作图像并生成不同的密度,然后将其放在drawable-wNNNdp-?dpi文件夹中,其中NNN-屏幕宽度和 - l, m, h, xh, xxh, xxxh dpi. -l,m,h,xh,xxh,xxxh dpi。 Exactly folders drawable-wNNNdp-?dpi is the answer 正是文件夹drawable-wNNNdp-?dpi是答案

Don't give fix size to imageview.Give imageview's height and width wrap_content in xml.... 不要给imageview固定大小。给xml中的imageview的高度和宽度wrap_content ....

<ImageView
android:id="@+id/img"
android:src="@drawable/splash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM