[英]Picasso won't show image from imgur
這是我使用的代碼,庫是從jar導入的,圖像鏈接工作正常,我什至在AndroidManifest.xml中添加了Internet權限。 問題是,當我啟動該應用程序時,它打開和關閉而沒有顯示任何內容。
package my.pkg.name;
import com.squareup.picasso.*;
import android.R.id.*;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.id.immagine);
ImageView targetImageView = (ImageView) findViewById(R.id.immagine);
String internetUrl = "http://i.imgur.com/DvpvklR.png";
Picasso
.with(this)
.load(internetUrl)
.into(targetImageView);
}
}
這是布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="just a string"
/>
<ImageView
android:id="@+id/immagine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="213"
/>
</LinearLayout>
謝謝
setContentView(R.id.immagine);
是錯的。 通常,您將R.layout.something
放入setContentView
。
另外,請記住,除了@eriuzo所說的Layout
之外,這可能是由於Activity
引起的:
public class MainActivity extends Activity
對於這些情況,應該檢查日志貓是否出了問題。但是,可以將其與AppCompatActivity
一起使用來解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.