您的位置:首页 > 其它

(droid分享)新浪微博开发系列【十二】之图片浏览

2012-09-26 20:50 337 查看
该篇是是图片浏览界面,好了,贴代码,在此说明一下,可能代码里调用一些方法在本篇中没有,但是全部在我的代码里,也不要索取图片,要看全部代码的请移步/article/8913211.html

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:orientation="vertical">

<LinearLayout

android:layout_width="fill_parent"

android:layout_height="41dp"

android:baselineAligned="false"

android:background="@drawable/bg_activitycontent">

<RelativeLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="2"

android:background="#BB768e95">

<Button

android:id="@+id/returnBtn"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:text="@string/imageViewActivity_close"

android:textColor="#ffffff"

android:background="@drawable/bg_btn">

</Button>

</RelativeLayout>

<RelativeLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="1"

android:background="#BB768e95" >

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:text="@string/imageViewActivity_view"

android:textColor="#ffffff" >

</TextView>

<ProgressBar

android:id="@+id/loadImageprogressBar"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:visibility="invisible"

android:layout_toLeftOf="@+id/textView1" />

</RelativeLayout>

<RelativeLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:layout_weight="2"

android:background="#BB768e95">

<Button

android:id="@+id/saveBtn"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:text="@string/imageViewActivity_save"

android:textColor="#ffffff"

android:background="@drawable/bg_btn">

</Button>

</RelativeLayout>

</LinearLayout>

<RelativeLayout

android:layout_width="fill_parent"

android:layout_height="fill_parent">

<com.czu.zoom.ImageZoomView

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/pic"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

</com.czu.zoom.ImageZoomView>

<ZoomControls

android:id="@+id/zoomCtrl"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_alignParentBottom="true">

</ZoomControls>

</RelativeLayout>

</LinearLayout>



package com.czu.sinaweibo;

import com.czu.downloadiconimage.AsyncImageLoader;

import com.czu.sinaweibo.R;

import com.czu.utils.Utils;

import com.czu.zoom.ImageZoomView;

import com.czu.zoom.SimpleZoomListener;

import com.czu.zoom.ZoomState;

import android.app.Activity;

import android.content.Intent;

import android.graphics.Bitmap;

import android.os.Bundle;

import android.view.View;

import android.view.Window;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.ZoomControls;

public class ImageViewActivity extends Activity {

private ImageZoomView imageZoomView = null;

private ZoomState zoomState = null;

private SimpleZoomListener simpleZoomListener = null;

/** 返回按钮 */

private Button returnButton = null;

/** 保存按钮 */

private Button saveButton = null;

/* 对话框 */

// private ProgressDialog progressDialog;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

/* 设置没有标题栏 */

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.imageview_activity);

imageZoomView = (ImageZoomView) this.findViewById(R.id.pic);

Intent intent = this.getIntent();

Bundle bundle = intent.getExtras();

final String imageUrl = bundle.getString("ImageUrl");

AsyncImageLoader asyncImageLoader = new AsyncImageLoader(imageUrl,

imageZoomView, false);

asyncImageLoader.setImage();

zoomState = new ZoomState();

imageZoomView.setZoomState(zoomState);

simpleZoomListener = new SimpleZoomListener();

simpleZoomListener.setZoomState(zoomState);

imageZoomView.setOnTouchListener(simpleZoomListener);

resetZoomState();

ZoomControls zoomCtrl = (ZoomControls) findViewById(R.id.zoomCtrl);

zoomCtrl.setOnZoomInClickListener(new OnClickListener() {

@Override

public void onClick(View view) {

float z = zoomState.getZoom() + 0.25f;

zoomState.setZoom(z);

zoomState.notifyObservers();

}

});

zoomCtrl.setOnZoomOutClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

float z = zoomState.getZoom() - 0.25f;

zoomState.setZoom(z);

zoomState.notifyObservers();

}

});

/* 退出按钮 */

returnButton = (Button) this.findViewById(R.id.returnBtn);

returnButton.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

finish();

}

});

/** 保存按钮 */

saveButton = (Button) this.findViewById(R.id.saveBtn);

saveButton.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

Bitmap bitmap = imageZoomView.getBitmap();

Utils.SaveBitmap(ImageViewActivity.this,bitmap, imageUrl);

}

});

}

private void resetZoomState() {

zoomState.setPanX(0.5f);

zoomState.setPanY(0.5f);

zoomState.setZoom(1f);

zoomState.notifyObservers();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: