我想使用Picasso将Url中的图像加载到一个简单的Imageview中。但不幸的是,我面临一些问题。我已包含以下日志和相关代码。我已授予Internet许可并使用了最新版的毕加索。

enter image description here

MainActivity.java

package com.example.picassotest;

import androidx.appcompat.app.AppCompatActivity;

import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {

    ImageView imgView;
    TextView txtView;

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

        imgView = findViewById(R.id.img_view);
        txtView = findViewById(R.id.txtview);
        Picasso.get().setLoggingEnabled(true);
        Picasso.get().load("https://images.unsplash.com/photo-1500100586562-f75ff6540087?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=3589&q=80").into(imgView);
    }
}


activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/img_view"
        app:layout_constraintStart_toStartOf="@id/img_view"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher_round"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txtview"
        app:layout_constraintTop_toBottomOf="@id/img_view"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:text="Hey"
        />


</androidx.constraintlayout.widget.ConstraintLayout>


日志

链接:https://pastebin.com/820tP9Jd

最佳答案

在清单中使用

android:usesCleartextTraffic="true

关于java - picasso 未在ImageView中加载图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59755692/

10-09 12:57