码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2016-02-16 14:43:07      阅读:367      评论:0      收藏:0      [点我收藏+]

标签:

              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 加载网络图片时 宽度固定 按等比例显示

标签:

原文地址:http://www.cnblogs.com/yangqi0226/p/5192488.html

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