码迷,mamicode.com
首页 > 其他好文 > 详细

点击头像显示大图Dialog

时间:2015-02-07 17:20:30      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

1、实现效果

点击头像 弹出全屏dialog,长按图片弹出“保存图片对话框”,短按dialog消失。

package com.example.widget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.ImageView;

import com.kuangren.real.R;
import com.will.ui.view.ChatDialog;

public class HeadDialog extends Dialog {

    private ImageView imageView;
    Context context;
    private Bitmap bitmap;

    public HeadDialog(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        this.context = context;
    }

    public HeadDialog(Context context, int theme) {
        super(context, theme);
        this.context = context;
    }

    private ChatDialog alertDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.head_dialog);
        imageView = (ImageView) findViewById(R.id.dialog_head);
        if(bitmap!=null){
            imageView.setImageBitmap(bitmap);
        }
        // 这里要写全,
        imageView.setOnClickListener(new android.view.View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                HeadDialog.this.dismiss();
            }
        });
        imageView.setOnLongClickListener(new OnLongClickListener() {

            @Override
            public boolean onLongClick(View arg0) {
                // TODO Auto-generated method stub

                alertDialog.show();

                return false;
            }
        });
    }

    public ImageView getImageView() {
        return imageView;
    }

    public ChatDialog getAlertDialog() {
        return alertDialog;
    }

    public void setAlertDialog(ChatDialog alertDialog) {
        this.alertDialog = alertDialog;
    }

    public Bitmap getBitmap() {
        return bitmap;
    }

    public HeadDialog setBitmap(Bitmap bitmap) {
        this.bitmap = bitmap;
        return this;
    }

}

 

调用

HeadDialog dialog =new 
dialog.setAlertDialog(alertDialog);
dialog.setBitmap(bitmap).show();

 

 

注意:

android.view.View.OnClickListener与content.DialogInterface.OnClickListener()冲突

使用时带上全路径

 

点击头像显示大图Dialog

标签:

原文地址:http://www.cnblogs.com/xingyyy/p/4278942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!