【发布时间】:2020-06-28 13:41:53
【问题描述】:
由于某种原因,我无法在 android studio 中显示来自 URL 的图像。我尝试的一切都没有发生。首先我尝试了“Picasso”,然后我尝试了“Universal Image Loader”,然后我尝试了“Firebase Storage”和“Glide”。但我无法在其中任何一个中显示互联网上的图像。应用程序使用这 4 种方法(Picasso、Universal Image Loader、Firebase Storage),但它不显示图像。
我将只在下面显示毕加索,以便问题不长,但如果您愿意,我可以将它们全部显示。有什么我忽略的吗?或者可能需要一些我不知道的简单设置?所以无论我尝试什么,是什么阻止我显示图像。
Gradle
apply plugin: 'com.android.application'
android { compileSdkVersion 29 buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.deneme.goruntudeneme"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}}
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.squareup.picasso:picasso:2.71828'
}
XML
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:id="@+id/my_image_view"
android:layout_width="350dp"
android:layout_height="350dp"
android:scaleType="centerCrop">
</ImageView></LinearLayout>
Java
public class MainActivity extends AppCompatActivity {
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(ImageView)findViewById(R.id.my_image_view);
Picasso.get().load("https://via.placeholder.com/500").into(imageView);
}}
权限
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
【问题讨论】:
-
android:usesCleartextTraffic="true"将其放入您的应用程序清单中 -
它正在工作,图像正在显示,我在代码中没有看到任何错误。
-
@Ashish 这个问题我处理得非常好。我按照你说的做了,我的问题解决了。谢谢。
标签: android android-studio firebase-storage picasso universal-image-loader