图片无论如何都不显示(Picasso,Glide,Async)

huangapple go评论80阅读模式
英文:

Image not showing no matter what(Picasso,Glide,Async)

问题

不管我做什么,图片就是不显示。

我已经写了最简单的代码来进行测试,但我确实需要一些帮助。

我没有收到任何错误和崩溃,所以我不知道该怎么办。

我尝试过使用 Glide 和 Asynce,但都没有成功。

顺便说一下,在 Android 清单文件中添加了用户权限:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>

谢谢!

public class MainActivity extends AppCompatActivity {

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

        ImageView myImage = (ImageView) findViewById(R.id.mImageView);
        Picasso.get().load("https://i.imgur.com/tGbaZCY.jpg").into(myImage);
    }
}

ImageView 代码:

<ImageView
    android:id="@+id/mImageView"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginStart="32dp"
    android:layout_marginLeft="32dp"
    android:layout_marginTop="32dp"
    android:layout_marginEnd="32dp"
    android:layout_marginRight="32dp"
    android:layout_marginBottom="32dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

ImageView 图片链接:

https://ibb.co/gwbfgWR

问题出在模拟器上!!!

简直不敢相信,感觉自己太菜了哈哈。

英文:

No matter what I do,the picture just doesn't want to show.

I have done the simplest code just for the test and I can really use some help.

I am getting no errors and no crashes,so I have no clue what to do.

I tried to use Glide and Asynce also but with no success.

btw,I added user permission on android manifest:

&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;&gt;&lt;/uses-permission&gt;
&lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot;&gt;&lt;/uses-permission&gt;

Thank you!

public class MainActivity extends AppCompatActivity {


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

        ImageView myImage = (ImageView) findViewById(R.id.mImageView);
        Picasso.get().load(&quot;https://i.imgur.com/tGbaZCY.jpg&quot;).into(myImage);
    }
}

ImageView Code:

ImageView
    android:id=&quot;@+id/mImageView&quot;
    android:layout_width=&quot;0dp&quot;
    android:layout_height=&quot;0dp&quot;
    android:layout_marginStart=&quot;32dp&quot;
    android:layout_marginLeft=&quot;32dp&quot;
    android:layout_marginTop=&quot;32dp&quot;
    android:layout_marginEnd=&quot;32dp&quot;
    android:layout_marginRight=&quot;32dp&quot;
    android:layout_marginBottom=&quot;32dp&quot;
    app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toTopOf=&quot;parent&quot;

ImageView :

https://ibb.co/gwbfgWR

THE EMULATOR IS THE PROBLEM!!!!!

Can't believe,I feel so noob haha

答案1

得分: 1

好的,我花了几个小时来找出问题所在。

模拟器是问题的源头!!!

我在手机上试了一下,可以运行!

下次我肯定会把手机设为默认。

感谢所有的回复者!!

英文:

Okay guys so I spent few hours trying to figure out what was the problem.

THE EMULATOR IS THE PROBLEM!!!!!

I tried the app on my phone and it works!

Next time I definitely going to use my phone as default.

Thanks for all the replayers!!

答案2

得分: 0

试试这个

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/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:srcCompat="@tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>


MainActivity

public class MainActivity extends AppCompatActivity {

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

        ImageView myImage = (ImageView) findViewById(R.id.imageView);
        Glide.with(MainActivity.this)
                .load("https://i.imgur.com/tGbaZCY.jpg")
                .into(myImage);

    }
}

添加这部分

implementation 'com.github.bumptech.glide:glide:4.11.0'

在你的清单文件中

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
英文:

Try this

Xml

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
    xmlns:tools=&quot;http://schemas.android.com/tools&quot;
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot;
    tools:context=&quot;.MainActivity&quot;&gt;


    &lt;ImageView
        android:id=&quot;@+id/imageView&quot;
        android:layout_width=&quot;wrap_content&quot;
        android:layout_height=&quot;wrap_content&quot;
        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
        app:layout_constraintEnd_toEndOf=&quot;parent&quot;
        app:layout_constraintStart_toStartOf=&quot;parent&quot;
        app:layout_constraintTop_toTopOf=&quot;parent&quot;
        tools:srcCompat=&quot;@tools:sample/avatars&quot; /&gt;
&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;


MainActivity

public class MainActivity extends AppCompatActivity {

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

        ImageView myImage = (ImageView) findViewById(R.id.imageView);
        Glide.with(MainActivity.this)
                .load(&quot;https://i.imgur.com/tGbaZCY.jpg&quot;)
                .into(myImage);

    }
}

ADD this

implementation &#39;com.github.bumptech.glide:glide:4.11.0&#39;

In Your Manifest

&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
&lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot;/&gt;

huangapple
  • 本文由 发表于 2020年9月1日 22:30:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63689754.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定