英文:
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 图片链接:
问题出在模拟器上!!!
简直不敢相信,感觉自己太菜了哈哈。
英文:
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:
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
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("https://i.imgur.com/tGbaZCY.jpg").into(myImage);
}
}
ImageView Code:
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 :
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
<?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);
}
}
ADD this
implementation 'com.github.bumptech.glide:glide:4.11.0'
In Your Manifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论