android 击缩略图查看大图
2013-05-02 11:36
411 查看
android中点击缩略图查看大图的方法一般有两种,一种是想新浪微博list页面那样,弹出一个窗口显示大图(原activity为背景)。另一种就是直接打开一个新的activity显示大图。
1、第一种方法我们可以使用自定义的AlertDialog来实现,代码如下:
ImageView image=(ImageView)findViewById(R.id.small_image);
image.setOnClickListener(new OnClickListener() { // 点击放大
public void onClick(View paramView) {
LayoutInflater inflater = LayoutInflater.from(context);
View imgEntryView = inflater.inflate(R.layout.dialog_photo_entry, null);
// 加载自定义的布局文件
final AlertDialog dialog = new AlertDialog.Builder(context).create();
ImageView img = (ImageView)imgEntryView.findViewById(R.id.large_image);
imageDownloader.download("图片地址",img); // 这个是加载网络图片的,可以是自己的图片设置方法
dialog.setView(imgEntryView); // 自定义dialog
dialog.show();
// 点击布局文件(也可以理解为点击大图)后关闭dialog,这里的dialog不需要按钮
imgEntryView.setOnClickListener(new OnClickListener() {
public void onClick(View paramView) {
dialog.cancel();
}
});
}
});
对应的布局文件dialog_photo_entry内容为:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:layout_height="wrap_content" android:id="@+id/large_image "
android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true">
</ImageView>
</RelativeLayout>
2、另外一种打开一个新的activity的方法相对简单点,大图activity代码如下:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_photo_entry);
activity = this;
Bundle bundle = this.getIntent().getExtras();
if(bundle!=null){
picName = bundle.getString("picName"); //图片名
}
ImageView img = (ImageView)this.findViewById(R.id.large_image );
imageDownloader.download(
picName,img);
Toast toast = Toast.makeText(this, "点击图片即可返回",Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.show();
img.setOnClickListener(new View.OnClickListener() { // 点击返回
public void onClick(View paramView) {
activity.finish();
}
});
}
对应的布局文件dialog_photo_entry内容为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="@+id/entry_pic" android:layout_margin="0dip" android:padding="0dip">
<ImageView android:layout_height="wrap_content" android:id="@+id/large_image"
android:layout_marginTop="0dip" android:paddingTop="0dip"
android:adjustViewBounds="true"
android:layout_width="fill_parent">
</ImageView>
</ScrollView>
</LinearLayout>
1、第一种方法我们可以使用自定义的AlertDialog来实现,代码如下:
ImageView image=(ImageView)findViewById(R.id.small_image);
image.setOnClickListener(new OnClickListener() { // 点击放大
public void onClick(View paramView) {
LayoutInflater inflater = LayoutInflater.from(context);
View imgEntryView = inflater.inflate(R.layout.dialog_photo_entry, null);
// 加载自定义的布局文件
final AlertDialog dialog = new AlertDialog.Builder(context).create();
ImageView img = (ImageView)imgEntryView.findViewById(R.id.large_image);
imageDownloader.download("图片地址",img); // 这个是加载网络图片的,可以是自己的图片设置方法
dialog.setView(imgEntryView); // 自定义dialog
dialog.show();
// 点击布局文件(也可以理解为点击大图)后关闭dialog,这里的dialog不需要按钮
imgEntryView.setOnClickListener(new OnClickListener() {
public void onClick(View paramView) {
dialog.cancel();
}
});
}
});
对应的布局文件dialog_photo_entry内容为:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView android:layout_height="wrap_content" android:id="@+id/large_image "
android:layout_width="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true">
</ImageView>
</RelativeLayout>
2、另外一种打开一个新的activity的方法相对简单点,大图activity代码如下:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_photo_entry);
activity = this;
Bundle bundle = this.getIntent().getExtras();
if(bundle!=null){
picName = bundle.getString("picName"); //图片名
}
ImageView img = (ImageView)this.findViewById(R.id.large_image );
imageDownloader.download(
picName,img);
Toast toast = Toast.makeText(this, "点击图片即可返回",Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM, 0, 0);
toast.show();
img.setOnClickListener(new View.OnClickListener() { // 点击返回
public void onClick(View paramView) {
activity.finish();
}
});
}
对应的布局文件dialog_photo_entry内容为:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content"
android:id="@+id/entry_pic" android:layout_margin="0dip" android:padding="0dip">
<ImageView android:layout_height="wrap_content" android:id="@+id/large_image"
android:layout_marginTop="0dip" android:paddingTop="0dip"
android:adjustViewBounds="true"
android:layout_width="fill_parent">
</ImageView>
</ScrollView>
</LinearLayout>
相关文章推荐
- Android开发之--缩略图点击查看大图
- Android点击缩略图查看大图的缩放动画
- android开发:点击缩略图查看大图
- android开发:点击缩略图查看大图
- Android点击缩略图查看大图
- android开发:点击缩略图查看大图
- android开发:点击缩略图查看大图
- android 点击缩略图查看大图
- Android---文本中缩略图点击弹出大图效果实现
- WinForm版ListView图片查看小程序(用ListView显示某个文件夹中图片为缩略图,PictureBox显示大图)
- Android View 查看大图(支持拖拽,缩放,旋转)
- ListView图片查看小程序(用listview显示某个文件夹中图片为缩略图,picturebox显示大图)
- android webview加载html加载css样式&点击查看大图&点击查看全部大图
- 怎样实现textview里显示的缩略图,点击查看大图的效果
- android 查看图片缩略图
- Android下QQ空间查看大图特效
- android webview加载html图片自适应手机屏幕大小&点击查看大图
- Android 中 WebView 与 js 简单交互实现图文混排效果,解决图片自适应屏幕与查看大图问题
- Android dialog点击查看大图
- JQuery实现点击缩略图查看大图效果