2015-02-11 61 views
0

我使用可繪製文件夾中的圖像將圖像顯示到圖庫視圖。 mycode的如何在android中的圖庫視圖中顯示來自web的圖像

public class GalleryView extends Activity { 
Integer[] pics = { 
    R.drawable.antartica1, 
    R.drawable.antartica2, 
    R.drawable.antartica3, 
    R.drawable.antartica4, 
    R.drawable.antartica5, 
    R.drawable.antartica6, 
    R.drawable.antartica7, 
    R.drawable.antartica8, 
    R.drawable.antartica9, 
    R.drawable.antartica10 
}; 
ImageView imageView; 

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    Gallery ga = (Gallery)findViewById(R.id.Gallery01); 
    ga.setAdapter(new ImageAdapter(this)); 

    imageView = (ImageView)findViewById(R.id.ImageView01); 
    ga.setOnItemClickListener(new OnItemClickListener() { 



public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
long arg3) { 
Toast.makeText(getBaseContext(), 
    "You have selected picture " + (arg2+1) + " of Antartica", 
    Toast.LENGTH_SHORT).show(); 
imageView.setImageResource(pics[arg2]); 

} 

    }); 

} 



} 

但是我有一個ArrayList相似圖片

[http://sport24x7.com/nightclub/photos/ 9955917512-Gym-ChestWorkout_xxlarge.jpg, http://sport24x7.com/nightclub/photos/ 64557264beginner_gym_workout_legs_large.jpg, http://sport24x7.com/nightclub/photos/ 54809160intro-ez-bar.jpg] 

如何顯示在畫廊觀看這些圖像。任何人都可以幫助我做到這一點?

+0

您應該使用picasso庫: Picasso.with(context).load(「http://i.imgur.com/DvpvklR.png」).into(imageView); – mustafasevgi 2015-02-11 06:22:06

+0

畢加索網站:http://square.github.io/picasso/ – mustafasevgi 2015-02-11 06:22:34

+0

你應該遵循懶加載概念 – Boopathi 2015-02-11 06:28:26

回答

0

您應該下載圖像,然後使用圖庫進行顯示。
我建議您使用UIL

+0

這個答案應該是在評論 – user1140237 2015-02-11 06:18:45

+0

但我需要顯示XML不是網格視圖的圖庫查看圖像 – Hanzs 2015-02-11 06:49:03

0

請注意,Gallery視圖已棄用,不應再使用。

Here是如何使用的GridView來顯示圖像的簡單的教程。

關鍵概念是覆蓋getView並將您的圖像加載到ImageView。您可以使用Picasso輕鬆加載給定URL的圖像。

例如,在您的適配器的getView

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView); 
0

從網站下載圖像和流轉換爲Bitmap

嘗試下面的代碼。

URL imageUrl = new URL(item); 
HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection(); 
conn.setConnectTimeout(30000); 
conn.setReadTimeout(30000); 
conn.setInstanceFollowRedirects(true); 
InputStream is=conn.getInputStream(); 
Bitmap bmp = BitmapFactory.decodeStream(is); 

我會建議懶加載。嘗試Universal Image Loader

相關問題