0

ImageViewに画像を読み込もうとしましたが、画像のサイズが「adjustViewBounds」によって維持されているため、幅が小さく、高さの高い画像が大きすぎます。私は高さを制限したい。AdjustViewBoundsを使用したImageViewの問題

画像を全幅と可変高さで表示し、アスペクト比も維持したいと考えています。元の画像の60%で画像のサイズを変更しようとすると、同じスペースを使用しても大きすぎます。

実装コード:

<ImageView 
     android:id="@+id/iv_HomeFragment_PostGallery" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/tv_HomeFragment_ReadMore" 
     android:adjustViewBounds="true"/> 

GLIDEコード:

Glide.with(currentFragment) 
       .load(url) 
       .asBitmap() 
       .dontAnimate() 
       .placeholder(R.drawable.placeholder) 
       .diskCacheStrategy(DiskCacheStrategy.SOURCE) 
       .error(R.drawable.error_image) 
       .into(new SimpleTarget<Bitmap>() { 
        @Override 
        public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { 
         Bitmap resizeBitmap = resize(resource,(int)(width * 0.4f),(int)(height * 0.4f)); 
         viewHolder.ivGalleryPic.setImageBitmap(resizeBitmap); 
        } 
       }); 
+1

'android:scaleType =" fitCenter "'が動作しない場合は、スケールタイプの異なる値を試してみてください。 –

+0

@SaranSankaran働いていない。すべての "scaleType" –

答えて

0

あなたはアスペクト比を維持するために、これを試すことができます

<ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:adjustViewBounds="true" 
       android:src="@drawable/unnamed" /> 
     </LinearLayout> 
    </ScrollView> 
関連する問題