private void initWidth() { int screenWidth = ((MyApplication)getApplication()).screenWidth; if(0 == screenWidth){ DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); ((MyApplication)this.getApplication()).screenWidth = dm.widthPixels; screenWidth = dm.widthPixels; //得到宽度 } imageViewWidth = (screenWidth - (3*CommonUtil.dip2px(ProductListActivity.this, 10)))/2; }
//重新设置图像宽高 ViewGroup.LayoutParams params = holder.imgIconUrl0.getLayoutParams(); params.width = imageViewWidth; params.height = imageViewWidth; holder.imgIconUrl0.setLayoutParams(params); ImageLoaderUtil.displayBigImage(products.get(0).getIconUrl(), holder.imgIconUrl0, 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) {} @Override public void onLoadingCancelled(String imageUri, View view) {} });
原问题描述:我想在activity中改变图片视图的宽高属性,但是我用了一个方法后没有实现,应该要怎么实现呢?
解决方案:
在这段代码中,创建了一个新的实例并且设置了尺寸:
[java] view plaincopy
- // SET THE IMAGEVIEW DIMENSIONS
- int dimens = 120;
- float density = activity.getResources().getDisplayMetrics().density;
- int finalDimens = (int)(dimens * density);
- LinearLayout.LayoutParams imgvwDimens =
- new LinearLayout.LayoutParams(finalDimens, finalDimens);
- imgAlbumPhoto.setLayoutParams(imgvwDimens);
- // SET SCALETYPE
- imgAlbumPhoto.setScaleType(ScaleType.CENTER_CROP);
- // SET THE MARGIN
- int dimensMargin = 5;
- float densityMargin = activity.getResources().getDisplayMetrics().density;
- int finalDimensMargin = (int)(dimensMargin * densityMargin);
- LinearLayout.LayoutParams imgvwMargin =
- new LinearLayout.LayoutParams(finalDimens, finalDimens);
- imgvwMargin.setMargins
- (finalDimensMargin, finalDimensMargin, finalDimensMargin, finalDim
- ensMargin);
改变已存在的ImageView尺寸,使用这个:
[java] view plaincopy
- coupon_img.setLayoutParams(new LayoutParams(100, 100));
时间: 2024-11-04 13:14:51