android 获取网络图片显示在Gallery中
2010-09-14 23:52:00 来源:WEB开发网其实很简单,Gallery 里设置 setAdapter() 里面添加图片的资源,这需要继承BaseAdapter 重写里面的函数,值得一提的是需要写一个xml
< ?xml version="1.0" encoding="utf-8"?>
< resources>
< declare-styleable name="Gallery">
< attr name="android:galleryItemBackground" />
< /declare-styleable>
< /resources>
主要代码:
private Gallery myGallery01;
/* 图片资源 */
private String[] myImageURL = new String[]
{
"http://www.chinajilin.com.cn/att/site1/20071116/"
+ "img-1196620280651.jpg",
"http://image.szonline.net/UploadFile/album/2010/7/71315/2/"
+ "20100702111104_64763.jpg",
"http://www.fzl020.com/uploads/userup/0904/"
+ "30031RI2U.jpg",
"http://lh6.ggpht.com/_2N-HvtdpHZY/SZ357lAfZNE/AAAAAAAABOE/"
+ "dfxBtdINgPA/s144-c/20090220.jpg",
"http://news.xinhuanet.com/travel/2008-03/18/"
+ "xin_0620305181402218149794.jpg" };
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myGallery01 = (Gallery) findViewById(R.id.myGallery01);
myGallery01.setAdapter(new myInternetGalleryAdapter(this));
}
/* BaseAdapter */
public class myInternetGalleryAdapter extends BaseAdapter
{
private Context myContext;
private int mGalleryItemBackground;
/* 构造函数 Context */
public myInternetGalleryAdapter(Context c)
{
this.myContext = c;
// 检索 这方面的主题风格的属性
TypedArray a = myContext
.obtainStyledAttributes(R.styleable.Gallery);
//得到资源标识
mGalleryItemBackground = a.getResourceId(
更多精彩
赞助商链接