Android 加载网络图片时 宽度固定 按等比例显示

              View v = LayoutInflater.from(TourBuyDetailsActivity.this ).inflate(R.layout.tour_details_header_img_item,null);
                        final ImageView imageView = (ImageView) v.findViewById(R.id.content_pic);
                        ImageLoader.getInstance().displayImage(travelMode.getMedia().image.get(i), imageView, new ImageLoadingListener() {
                            @Override
                            public void onLoadingStarted(String imageUri, View view) {

                            }

                            @Override
                            public void onLoadingFailed(String imageUri, View view, FailReason failReason) {

                            }

                            @Override
                            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                            // TODO Auto-generated method stub

                                DisplayMetrics metric = new DisplayMetrics();
                                getWindowManager().getDefaultDisplay().getMetrics(metric);
                                int pxWidth = metric.widthPixels;
                                float ratio = (float)pxWidth/(float)loadedImage.getWidth();
                                float imageHeight = loadedImage.getHeight()*ratio;

                                ViewGroup.LayoutParams lp = imageView.getLayoutParams();
                                lp.width = pxWidth;
                                lp.height = (int)imageHeight;
                                imageView.setLayoutParams(lp);
                            }

                            @Override
                            public void onLoadingCancelled(String imageUri, View view) {

                            }
                        });
                        mImageLinearLayout.addView(v);

 

你可能感兴趣的:(Android 加载网络图片时 宽度固定 按等比例显示)