【问题标题】:Android Picasso library not loading image from URLAndroid Picasso 库未从 URL 加载图像
【发布时间】:2018-07-14 14:22:37
【问题描述】:

由于某种原因,毕加索没有从 URL 加载图像。我只看到一个空白的白色屏幕。 我已经尝试过解决这些以前的问题,但对我没有任何帮助。

下面是Activity的Java代码:

public class MainActivity extends AppCompatActivity {

    ImageView mImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mImageView = (ImageView) findViewById(R.id.picassoImage);
        Picasso.with(this).load("https://futurestud.io/images/books/picasso.png").into(mImageView);
    }
}

这里是 XML 布局代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.sourabh.usingpicasso.MainActivity">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/picassoImage"/>

</LinearLayout>

注意:-

  1. 我尝试了不同的 URL,但没有成功。

  2. 我已经在 Manifest.XML 中设置了 Internet 的权限

  3. 当我将errorPicasso.with(this).load("https://futurestud.io/images/books/picasso.png").into(mImageView) 链接时(即

    毕加索.with(this).load("https://futurestud.io/images/books/picasso.png") .error(R.drawable.ic_launcher_background)。 进入(mImageView);

) 并将可绘制的图像传递给它,从而显示可绘制的图像。似乎毕加索不只是从 URL 加载图像。

【问题讨论】:

  • 我无法在手机上复制该问题。图片加载正常。
  • 未在 Android Emulator Nexus API 25 上加载。
  • 尝试检查 Android 真机 @SourabhKhandelwal

标签: android android-studio picasso android-studio-3.0


【解决方案1】:

有关毕加索图书馆的详细信息,请查看https://github.com/square/picasso

也许您使用的是以前的版本。请在您的应用级 build.gradle 文件中添加以下行。

implementation 'com.squareup.picasso:picasso:2.71828'

然后在您的活动中执行此操作。

public class MainActivity extends AppCompatActivity {

    ImageView mImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mImageView = (ImageView) findViewById(R.id.picassoImage);
        Picasso.get()
                .load("https://futurestud.io/images/books/picasso.png")
                .placeholder(R.drawable.placeholder_image)
                .error(R.drawable.error_image)
                .into(mImageView);
    }
}

【讨论】:

    【解决方案2】:

    即使我在 Android 模拟器(设备:Pixel 3a XL)上也遇到了这个问题,并且在尝试解决这个问题几个小时后,然后我在正在加载图像的真实设备上运行了该应用程序

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-08
      • 1970-01-01
      • 2018-07-06
      相关资源
      最近更新 更多