如何从通过drawable加载的图像中获得适当的分辨率?

时间:2015-08-03 21:22:29

标签: picasso

我在Android应用程序中使用Picasso。我正在测试的设备是三星平板电脑(SM-T110),并且运行的是Android版本4.2.2。

在一些地方,我将图像加载到ImageView,其中图像在网上,因此我使用URL。这非常有效。一切似乎都很好。

我用这个设置图像:

    <ImageView
        android:id="@+id/news_list_image_view"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:scaleType="fitXY"
        android:layout_centerHorizontal="true"
        android:src="@drawable/gf_logo"
        tools:ignore="ContentDescription" />

并且图像看起来很棒。

现在我有:

    <ImageView
        android:id="@+id/news_list_image_view"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:scaleType="fitXY"
        android:layout_centerHorizontal="true"
        tools:ignore="ContentDescription" />

    Picasso
            .with(getBaseContext())
            .load(R.drawable.gf_logo)
            .resize(200, 200)
            .placeholder(R.drawable.happy_me)
            .error(R.drawable.happy_me)
            .into((ImageView)findViewById(R.id.news_list_image_view));

在我的活动类中,图像看起来是错误的分辨率。它看起来非常模糊。

我有这些版本的图片:

 app/src/main/res/drawable/gf_logo.png
 app/src/main/res/drawable-ldpi/gf_logo.png
 app/src/main/res/drawable-mdpi/gf_logo.png
 app/src/main/res/drawable-hdpi/gf_logo.png
 app/src/main/res/drawable-xhdpi/gf_logo.png
 app/src/main/res/drawable-xxhdpi/gf_logo.png
 app/src/main/res/drawable-xxxhdpi/gf_logo.png

我希望我可以删除图形的“drawable / gf_logo.png”并且Picasso会做正确的事情,看看哪个图像用于解析设备,但这不起作用。

有没有办法让毕加索使用具有当前设备所需分辨率的图像?有没有办法让它停止使用“drawable / gf_logo.png”版本?如果我尝试删除该文件的副本,Android Studio会抱怨上面的Picasso调用正在使用该图像并且删除不安全。

BTW,我的gradle文件以此开头:

 android {
     compileSdkVersion 22
     buildToolsVersion "22.0.1"

     defaultConfig {
         applicationId "com.xyzzy.xyzzy"
         minSdkVersion 14
         targetSdkVersion 22
         versionCode 1
         versionName "1.0"

0 个答案:

没有答案
相关问题