点击小图显示大图 Alertdialog 全屏都可以

项目当中遇到了点击小图显示大图的需求,找个半天没有合适的 后来还是自己搞吧。。

直接上代码。。。


 public void smallImgClick(View v) {
       //有背景图
        final AlertDialog dialog = new AlertDialog.Builder(this).create();
        ImageView imgView = getView();
        dialog.setView(imgView);
        dialog.show();

        // 全屏显示的方法
//     final Dialog dialog = new Dialog(this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
//     ImageView imgView = getView();
//     dialog.setContentView(imgView);
//     dialog.show();

        // 点击图片消失
        imgView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dialog.dismiss();
            }
        });
    }


    private ImageView getView() {
        ImageView imgView = new ImageView(this);
        imgView.setLayoutParams(new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT));

        InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
        Drawable drawable = BitmapDrawable.createFromStream(is, null);
        imgView.setImageDrawable(drawable);

        return imgView;
    }



你可能感兴趣的:(android,自定义View)