android开发:点击缩略图查看大图
2013-09-26 15:06
501 查看
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>
转载:http://autumnice.blog.163.com/blog/static/555200201241884057196/
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>
转载:http://autumnice.blog.163.com/blog/static/555200201241884057196/
相关文章推荐
- android开发:点击缩略图查看大图
- android开发:点击缩略图查看大图
- Android开发之--缩略图点击查看大图
- android开发:点击缩略图查看大图
- Android开发之文本中缩略图点击弹出大图效果实现
- android 点击缩略图查看大图
- Android点击缩略图查看大图的缩放动画
- Android点击缩略图查看大图
- [置顶] 【Android】Android开发启动app弹出一张广告图片,Dialog可以查看大图,查看某个图片功能
- ionic开发——点击图片查看大图
- android 击缩略图查看大图
- Android手机点击查看手机电量Demo,android开发小项目Test 利用广播
- 【Android】Android开发点击查看手机电量的小功能。学习广播的一个小技能小Demo
- Android开发之--读取文件夹下图片生成略缩图并点击显示大图
- [转载]Android开发之--读取文件夹下图片生成略缩图并点击显示大图
- 【jQuery】点击缩略图查看大图-imgbox
- android webview加载html图片自适应手机屏幕大小&点击查看大图
- iOS开发---点击查看缩略图
- Android---文本中缩略图点击弹出大图效果实现
- js 移动端漂亮input框上传本地,显示缩略图,点击可以查看大图