Vol*_*oob 11 layout android android-layout android-imageview android-screen-support
首先,我想提前道歉,因为我确信以前曾经问过这类问题,但即使我在这些问题上寻找约2周,我也无法弄清楚我做错了什么.
这是我在活动中加载图像的地方:
ImageView image = (ImageView) findViewById(R.id.shop_Image) ;
image.setScaleType(ImageView.ScaleType.CENTER_CROP) ;
String mDrawableName = data.vec.elementAt(id).fuenf ;
if ( mDrawableName.equals("leer") )
mDrawableName = "ic_launcher" ;
int resID = getResources().getIdentifier(mDrawableName , "drawable", etPackageName());
image.setImageResource(resID) ;
Run Code Online (Sandbox Code Playgroud)
这是xml文件:
<LinearLayout
android:id="@+id/shop_Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FDFDFD"
android:orientation="vertical" >
<ImageView
android:id="@+id/shop_Image"
android:contentDescription="@string/shop_image"
android:layout_width="match_parent"
android:layout_height="400dp"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:src="@drawable/ic_launcher" />
[...]
Run Code Online (Sandbox Code Playgroud)
这些是结果:
在Galaxy Nexus,Nexus 5或Samsung S3上,它看起来像这样:

在Razr I或HTC Desire X上,它看起来像这样:

我知道上面显示图像正确的设备有至少4.7英寸的显示器,而模糊图像的显示器都有4.3英寸或4英寸.
即使我将这些图像放在不同的可绘制文件夹中,我仍然会得到这些令人不快的结果.
如果需要进一步的代码示例,请告诉我.
PS:抱歉缺少突出显示,我还是新手:)
在谷歌上快速搜索让我知道这些事实:
Desire X 规格: 480 x 800 pixels, 4.0 inches (~233 ppi pixel density)- 所以,它是一个hdpi 设备 Samsung S3 规格:720 x 1280 pixels, 4.8 inches (~306 ppi pixel density)- 所以,它是一个xhdpi设备
现在,您应该阅读以下内容:developer.android.com/guide/practices/screens_support.html。
一个非常快速的解决方法可能是:将图像放在/res/drawable-xhdpi文件夹中(如果您没有文件夹,只需创建它)。
还要考虑:
图像应以适当的 dpi 分辨率保存。
一个常见的错误是让它们处于72 dpi或96 dpi的标准(不足)分辨率。
hdpi图像分辨率应为240 dpi,xhdpi图像分辨率应为320 dpi,以正确显示和缩放。
那么该怎么办?
更改较大图像的分辨率,而不更改其大小(触摸分辨率时会自动缩放 - 因此,将其重置为 1280*800)。
然后通过更改分辨率(它应该缩小到正确的大小480*854 - 只需剪掉超过 54 个像素 - 顶部的 27 个像素和底部的 27 个像素),从中制作出较小的图像。
一旦您将正确的图像放入正确的文件夹中,现在一切都应该很合适。
| 归档时间: |
|
| 查看次数: |
1001 次 |
| 最近记录: |