private Gallery myGallery01; @Override ??? myGallery01 = (Gallery) findViewById(R.id.myGallery01); /* BaseAdapter */ ??? private Context myContext; ??? /* 构造函数 Context */ ???? // 返回 TypedArray? ??? /* */ ??? /* ID */ ??? public long getItemId(int position) ??? /* */ ????? ImageView imageView = new ImageView(this.myContext); ????? // 填充ImageView ? 转自:http://hi.baidu.com/cq_yajun/blog/item/d90923f98d3c0969034f5683.html
/* 图片资源 */
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" };
public void onCreate(Bundle savedInstanceState)
{
??? super.onCreate(savedInstanceState);
??? setContentView(R.layout.main);
??? myGallery01.setAdapter(new myInternetGalleryAdapter(this));
}
public class myInternetGalleryAdapter extends BaseAdapter
{
??? private int mGalleryItemBackground;
??? public myInternetGalleryAdapter(Context c)
??? {
????? this.myContext = c;
????? // 检索 这方面的主题风格的属性
????? TypedArray a = myContext?
????????? .obtainStyledAttributes(R.styleable.Gallery);
?????
????? //得到资源标识
????? mGalleryItemBackground = a.getResourceId(
????????? R.styleable.Gallery_android_galleryItemBackground, 0);
????? a.recycle();
??????
??? }
??? public int getCount()
??? {
????? return myImageURL.length;
??? }
??? public Object getItem(int position)
??? {
????? return position;
??? }
??? {
????? return position;
??? }
??? public float getScale(boolean focused, int offset)
??? {
????? /* Formula: 1 / (2 ^ offset) */
????? return Math.max(0, 1.0f / (float) Math.pow(2, Math
????????? .abs(offset)));
??? }
??? public View getView(int position, View convertView,
??????? ViewGroup parent)
??? {
????? /* ImageView */
????? try
????? {
??????? URL aryURI = new URL(myImageURL[position]);
??????? /* 打开连接 */
??????? URLConnection conn = aryURI.openConnection();?
??????? conn.connect();
??????? /* 转变为 InputStream */
??????? InputStream is = conn.getInputStream();
??????? /* 将InputStream转变为Bitmap */
??????? Bitmap bm = BitmapFactory.decodeStream(is);
??????? /* 关闭InputStream */
??????? is.close();
??????? /*添加图片*/
??????? imageView.setImageBitmap(bm);
????? } catch (IOException e)
????? {
??????? e.printStackTrace();
????? }
????? imageView.setScaleType(ImageView.ScaleType.FIT_XY);
????? /* 设置布局参数*/
????? imageView.setLayoutParams(new Gallery.LayoutParams(200, 150));
????? /* 设置背景资源 */
????? imageView.setBackgroundResource(mGalleryItemBackground);
????? return imageView;
??? }
}
详细解决方案
android 获取网络图片展示在Gallery中
热度:47 发布时间:2016-05-01 13:47:11.0
相关解决方案
- android 读取byte[]中的元素解决方案
- android 标题栏兑现方式
- android 中Activity向BroadcastReceiver发送数据,该怎么解决
- Android 4.0 为什么模拟器老是提示小弟我谷歌拼音输入法已停止
- android:getSharedPreferences() 这是哪个类的方法解决思路
- android 怎么判断一个程序是否联网
- android 大量数据按周分组,该如何解决
- android RadioButton如何设置默认选中
- ksoap2-android-这个包,连接webService怎么设置超时
- android 怎么重新设置锚点
- android UI界面设计解决方案
- android 图片对象获取的有关问题
- android 怎么调用淘宝支付宝接口
- Android 沿袭InputMethodService自定义输入法
- android 关于服务连接的疑义
- android 两个activity如何通信
- android 怎么实现对view的放大和缩小
- android 教程解决方法
- android ID,该如何处理
- 准备复习2-3个月,看java+android,请问有经验者,怎么看效果最好》
- android UI线程与AsyncTask的有关问题
- android(java)中的java.net能不能和c#的system.net.sockets进行tcp通信,该如何解决
- android ListView 中的onItemClick Intent 没法跳转
- android(java) 中文乱码的有关问题
- c#c++,android,ios(iphone),php,java视屏课程 散分
- android Post文件到ASP.NET的有关问题,能收到参数收不到文件
- RIM 替 Android 开发者提供免费的 PlayBook!2月13日前
- android 动态设立控件高度
- Android test project 编译方法
- android -相机使用教程(1)解决方法