If you write a list and click an image to preview the image

Source: Internet
Author: User

If you write a list and click an image to preview the image

Can be written in the form of inheriting AlertDialog:

Click a chart:

Public void onClick (View v) {viewBigsizeBmp (ImageView) v ). getDrawable (), Constants. preview_bmp _dir_suffix);} private void viewBigsizeBmp (Drawable drawable, String suffix) {final String sdDir = Utils. getSDPath (); final String saveDir = TextUtils. isEmpty (sdDir )? MCacheDir: sdDir + suffix; if (mBlog! = Null & mBlog. pic! = Null) {ImageViewerDialog dialog = new ImageViewerDialog (context, mBlog. pic, saveDir, drawable, suffix); // mBlog. pic is the image request address, such as success (true); dialog. show (); dialog. setOnCancelListener (new alertdiener. onCancelListener () {@ Overridepublic void onCancel (DialogInterface dialog) {}}); WindowManager. layoutParams lp = dialog. getWindow (). getAttributes (); lp. width = context. getResources (). getDimensionPixelSize (R. dimen. dialog_width); lp. height = context. getResources (). getDimensionPixelSize (R. dimen. dialog_height); dialog. getWindow (). setAttributes (lp );}}

Then write the Dialog:

Public class ImageViewerDialog extends AlertDialog {private Context context; private LayoutInflater inflater; private LinearLayout layout; private ImageView iv; private ProgressBar pb; private String uri; private AsyncTask
 
  
LoadPicTask; // String picfilePath; public boolean loadPictureRunning; private boolean finishPicLoad; private boolean isRedirectBlog; // private File downloadedImage; private LoadPictureTask mldPicTsk; private String mSaveDir; protected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); this. setContentView (layout); try {new loadpicturetask(cmd.exe cute ();} catch (RejectedExecutionException e) {}} private class LoadPictureTask extends AsyncTask
  
   
{Protected Object [] doInBackground (Object... args) {Bitmap bmp = null; try {bmp = Utils. getPreviewBitmap (uri, context. getCacheDir (). getAbsolutePath (), context, null, false, Constants. preview_bmp _dir_suffix);} catch (Exception e) {// Utils. loge (e); return null;} return new Object [] {bmp};} protected void onPostExecute (Object [] objs) {loadPictureRunning = false; if (objs! = Null & objs [0]! = Null) {pb. setVisibility (View. GONE); iv. setImageBitmap (Bitmap) objs [0]); finishPicLoad = true ;}} protected void onPreExecute () {super. onPreExecute () ;}} public ImageViewerDialog (Context context, String uri, String dir, Drawable drawable, String suffix) {super (context); this. context = context; this. mSaveDir = dir; inflater = LayoutInflater. from (context); layout = (LinearLayout) inflater. inflate (R. layout. imageviewerdialog, null); iv = (ImageView) layout. findViewById (R. id. ivImage); iv. setOnClickListener (new ImageView. onClickListener () {public void onClick (View v) {// TODO Auto-generated method stubdismiss () ;}}); pb = (ProgressBar) layout. findViewById (R. id. progressBar01); pb. setBackgroundDrawable (drawable); this. uri = uri ;}}
  
 

Layout of this Dialog:

 
  
  
 

:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.