从网络获取图片的相册。我查过了ImageSwitcher。
但是请宽恕我没有找到适用于网络图片地址的方法。所以改用 ImageView了。
首先我们要有xml文件。(这个随意)
附上我的
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/relativeLayout1" >
<ImageView
android:id="@+id/imageSwitcher1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
</ImageView>
</RelativeLayout>
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/picture_left"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="54dp"
android:background="@drawable/left" />
<Button
android:id="@+id/picture_right"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="54dp"
android:background="@drawable/right" />
</RelativeLayout>
</RelativeLayout>
图片 right 和 left 都是图片。图标。
我们将图片地址存储在一个list集合里面。
还有一个用于标识的 int 类型 索引 index
private ArrayList<String> mList;
private int index =0;
然后我们需要将网络图片的url给浓缩成一个 图片格式 名字叫bitmap。
这时我们需要用到这个方法
public static Bitmap getHttpBitmap(String url) {
Bitmap bitmap = null;
try {
URL myFileUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setConnectTimeout(0);
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
return bitmap;
}
有了这个方法。我们需要将图片给填充。这个时候需要用到
Image.setImageBitmap(Bitmap bitmap)
这个方法来进行填充。
这里再附加上相册的处理办法。图片转换的处理办法
public void onClick(View view) {
// TODO Auto-generated method stub
if(view == picUp){
if(index == 0){
index = index + 1;
Bitmap bitmap =getHttpBitmap(mList.get(index));
picture.setImageBitmap(bitmap);
}else{
index = index - 1;
Bitmap bitmap =getHttpBitmap(mList.get(index));
picture.setImageBitmap(bitmap);
}
}
if(view == picDown){
if(index +1 == mList.size()){
index = index - 1;
Bitmap bitmap =getHttpBitmap(mList.get(index));
picture.setImageBitmap(bitmap);
}else{
index = index + 1;
Bitmap bitmap =getHttpBitmap(mList.get(index));
picture.setImageBitmap(bitmap);
}
}
}
picUp是 ←这个箭头
picDown是 → 这个箭头。
转载请注明地址噢。亲。