图片未在 Android 中加载
Image not being loaded in Android
我是 android 的新手。我无法在我的应用程序中加载图片。主要代码为
package com.example.deepakchethan.imagedisplay;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
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.ImageContainer);
Picasso.with(getApplicationContext()).load("https://image.tmdb.org/t/p/w342/z4x0Bp48ar3Mda8KiPD1vwSY3D8.jpg").into(imageView);
}
}`
xml 是
`<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="com.example.deepakchethan.imagedisplay.MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ImageContainer"
tools:src="@mipmap/ic_launcher"/>
</RelativeLayout>`
但是图片还是没有加载。现在要做什么。请告诉。我需要学习。
您的代码没有任何问题。但是你有没有在清单文件中请求权限。如果您还没有添加,这很重要。将此代码输入到您的 minifest。
<uses-permission android:name="android.permission.INTERNET" />
如果问题仍然存在,请告诉我。
我是 android 的新手。我无法在我的应用程序中加载图片。主要代码为
package com.example.deepakchethan.imagedisplay;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
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.ImageContainer);
Picasso.with(getApplicationContext()).load("https://image.tmdb.org/t/p/w342/z4x0Bp48ar3Mda8KiPD1vwSY3D8.jpg").into(imageView);
}
}`
xml 是
`<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="com.example.deepakchethan.imagedisplay.MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ImageContainer"
tools:src="@mipmap/ic_launcher"/>
</RelativeLayout>`
但是图片还是没有加载。现在要做什么。请告诉。我需要学习。
您的代码没有任何问题。但是你有没有在清单文件中请求权限。如果您还没有添加,这很重要。将此代码输入到您的 minifest。
<uses-permission android:name="android.permission.INTERNET" />
如果问题仍然存在,请告诉我。