4

ImageViewがあります。コードはCardViewです。私のImageViewのscaleType = "fitXY"は、のプレロリポップデバイスでは機能しません。しかし、Lollipopではよりよく見えます。下の画像をご覧ください。
Image 私が上の画像に見てきたように、私は削除したい画像ビューの周りに白いパディングがあります。私は前のロリポップとポストリリップの両方のデバイスで同様のイメージを見たいと思います。問題を解消するのを手伝ってください。感謝:)ImageView scaleType = "fitXY"は、Cardviewの内部のプレロリポップデバイスでは機能しません。 Android

<android.support.v7.widget.CardView 
       android:layout_width="match_parent" 
       android:layout_height="160dp" 
       android:layout_marginRight="10dp" 
       android:layout_marginTop="6dp" 
       app:cardCornerRadius="10dp" 
       card_view:cardUseCompatPadding="false" 
       > 

       <ImageView 
        android:id="@+id/imgChat" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:scaleType="fitXY" 
        /> 
      </android.support.v7.widget.CardView> 
+0

からこのクラスを持っています角の半径を持つ矩形を使用したカスタムイメージビューとカスタムイメージビューのイメージを設定します。 – Vaibhavi

+0

@Vaibhavi ursの入力に感謝します:) –

答えて

0

... CardViewにコーナーつもり重なりに重なって、あなたはポストロリポップデバイスと同じ外観を取得します丸型画像ビューでImageViewを整理してください(Lollipopデバイスの場合と同様)。 OSのチェックを行い、イメージビューをカスタマイズすることができます。

基本的に我々はアプリケーションを作成するためにthisユニバーサル画像ローダーthisORグライド画像ローダを使用することができます。

ユニバーサル画像ローダーこの

ImageLoader imageLoader = ImageLoader.getInstance(); 
     imageLoader.init(ImageLoaderConfiguration.createDefault(MainActivity.this)); 
     DisplayImageOptions options = new DisplayImageOptions.Builder() 
       .displayer(new RoundedBitmapDisplayer(20))/// RoundedBitmapDisplayer IS THE CLASS BY WHICH , WE CAN CREATE THE ROUNDED CORNER OF THE IMAGEVIEW 
       .cacheInMemory(true) 
       .cacheOnDisk(true) 
       .build(); 
     imageLoader.displayImage("http://thedeveloperworldisyours.com/wp-content/uploads/scareface.jpeg", YOUR_IMAGEVIEW,options); 

グライドで画像ローダーようImageViewののコーナーを作成するには、デフォルトのRoundedCornersを提供し、我々はImageviewの円弧を作成するには、カスタムクラスを作成する必要があり、このlinkでは、カスタムImageView

Glide.with(this) 
       .load("http://thedeveloperworldisyours.com/wp-content/uploads/scareface.jpeg") 
       .bitmapTransform(new RoundedCornersTransformation(MainActivity.this,15, 2)) ///RoundedCornersTransformation IS THE CLASS, WHICH YOU NEED TO COPY INSIDE YOURS PROJECT, PLEASE FIND THIS CLASS ON ABOVE LINK AND I AM ALSO PROVIDING THE CLASS FOR IT 
       .into(YOUR_IMAGEVIEW); 
周りの丸い弧を作成するためにクラスを丸め見つけます

はグライドで丸みを帯びたコーナーを作成するために、我々は我々のプロジェクトでは、以下のクラスをコピーする必要があり、私はちょっとバージョンのコードを確認することができますし、それが21以下であれば、あなたが作るこのlink

import android.content.Context; 
import android.graphics.Bitmap; 
import android.graphics.BitmapShader; 
import android.graphics.Canvas; 
import android.graphics.Paint; 
import android.graphics.RectF; 
import android.graphics.Shader; 

import com.bumptech.glide.Glide; 
import com.bumptech.glide.load.Transformation; 
import com.bumptech.glide.load.engine.Resource; 
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; 
import com.bumptech.glide.load.resource.bitmap.BitmapResource; 

/** 
* Created by javiergonzalezcabezas on 2/4/16. 
*/ 
public class RoundedCornersTransformation implements Transformation<Bitmap> { 

    public enum CornerType { 
     ALL, 
     TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, 
     TOP, BOTTOM, LEFT, RIGHT, 
     OTHER_TOP_LEFT, OTHER_TOP_RIGHT, OTHER_BOTTOM_LEFT, OTHER_BOTTOM_RIGHT, 
     DIAGONAL_FROM_TOP_LEFT, DIAGONAL_FROM_TOP_RIGHT 
    } 

    private BitmapPool mBitmapPool; 
    private int mRadius; 
    private int mDiameter; 
    private int mMargin; 
    private CornerType mCornerType; 

    public RoundedCornersTransformation(Context context, int radius, int margin) { 
     this(context, radius, margin, CornerType.ALL); 
    } 

    public RoundedCornersTransformation(BitmapPool pool, int radius, int margin) { 
     this(pool, radius, margin, CornerType.ALL); 
    } 

    public RoundedCornersTransformation(Context context, int radius, int margin, 
             CornerType cornerType) { 
     this(Glide.get(context).getBitmapPool(), radius, margin, cornerType); 
    } 

    public RoundedCornersTransformation(BitmapPool pool, int radius, int margin, 
             CornerType cornerType) { 
     mBitmapPool = pool; 
     mRadius = radius; 
     mDiameter = mRadius * 2; 
     mMargin = margin; 
     mCornerType = cornerType; 
    } 

    @Override 
    public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) { 
     Bitmap source = resource.get(); 

     int width = source.getWidth(); 
     int height = source.getHeight(); 

     Bitmap bitmap = mBitmapPool.get(width, height, Bitmap.Config.ARGB_8888); 
     if (bitmap == null) { 
      bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 
     } 

     Canvas canvas = new Canvas(bitmap); 
     Paint paint = new Paint(); 
     paint.setAntiAlias(true); 
     paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP)); 
     drawRoundRect(canvas, paint, width, height); 
     return BitmapResource.obtain(bitmap, mBitmapPool); 
    } 

    private void drawRoundRect(Canvas canvas, Paint paint, float width, float height) { 
     float right = width - mMargin; 
     float bottom = height - mMargin; 

     switch (mCornerType) { 
      case ALL: 
       canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint); 
       break; 
      case TOP_LEFT: 
       drawTopLeftRoundRect(canvas, paint, right, bottom); 
       break; 
      case TOP_RIGHT: 
       drawTopRightRoundRect(canvas, paint, right, bottom); 
       break; 
      case BOTTOM_LEFT: 
       drawBottomLeftRoundRect(canvas, paint, right, bottom); 
       break; 
      case BOTTOM_RIGHT: 
       drawBottomRightRoundRect(canvas, paint, right, bottom); 
       break; 
      case TOP: 
       drawTopRoundRect(canvas, paint, right, bottom); 
       break; 
      case BOTTOM: 
       drawBottomRoundRect(canvas, paint, right, bottom); 
       break; 
      case LEFT: 
       drawLeftRoundRect(canvas, paint, right, bottom); 
       break; 
      case RIGHT: 
       drawRightRoundRect(canvas, paint, right, bottom); 
       break; 
      case OTHER_TOP_LEFT: 
       drawOtherTopLeftRoundRect(canvas, paint, right, bottom); 
       break; 
      case OTHER_TOP_RIGHT: 
       drawOtherTopRightRoundRect(canvas, paint, right, bottom); 
       break; 
      case OTHER_BOTTOM_LEFT: 
       drawOtherBottomLeftRoundRect(canvas, paint, right, bottom); 
       break; 
      case OTHER_BOTTOM_RIGHT: 
       drawOtherBottomRightRoundRect(canvas, paint, right, bottom); 
       break; 
      case DIAGONAL_FROM_TOP_LEFT: 
       drawDiagonalFromTopLeftRoundRect(canvas, paint, right, bottom); 
       break; 
      case DIAGONAL_FROM_TOP_RIGHT: 
       drawDiagonalFromTopRightRoundRect(canvas, paint, right, bottom); 
       break; 
      default: 
       canvas.drawRoundRect(new RectF(mMargin, mMargin, right, bottom), mRadius, mRadius, paint); 
       break; 
     } 
    } 

    private void drawTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 
     canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter), 
       mRadius, mRadius, paint); 
     canvas.drawRect(new RectF(mMargin, mMargin + mRadius, mMargin + mRadius, bottom), paint); 
     canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint); 
    } 

    private void drawTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 
     canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius, 
       mRadius, paint); 
     canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint); 
     canvas.drawRect(new RectF(right - mRadius, mMargin + mRadius, right, bottom), paint); 
    } 

    private void drawBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 
     canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom), 
       mRadius, mRadius, paint); 
     canvas.drawRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom - mRadius), paint); 
     canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint); 
    } 

    private void drawBottomRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 
     canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius, 
       mRadius, paint); 
     canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint); 
     canvas.drawRect(new RectF(right - mRadius, mMargin, right, bottom - mRadius), paint); 
    } 

    private void drawTopRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 
     canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius, 
       paint); 
     canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right, bottom), paint); 
    } 

    private void drawBottomRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 
     canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius, 
       paint); 
     canvas.drawRect(new RectF(mMargin, mMargin, right, bottom - mRadius), paint); 
    } 

    private void drawLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 
     canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius, 
       paint); 
     canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom), paint); 
    } 

    private void drawRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 
     canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius, 
       paint); 
     canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom), paint); 
    } 

    private void drawOtherTopLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 
     canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius, 
       paint); 
     canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius, 
       paint); 
     canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint); 
    } 

    private void drawOtherTopRightRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 
     canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius, 
       paint); 
     canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, right, bottom), mRadius, mRadius, 
       paint); 
     canvas.drawRect(new RectF(mMargin + mRadius, mMargin, right, bottom - mRadius), paint); 
    } 

    private void drawOtherBottomLeftRoundRect(Canvas canvas, Paint paint, float right, float bottom) { 
     canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius, 
       paint); 
     canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, bottom), mRadius, mRadius, 
       paint); 
     canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mRadius, bottom), paint); 
    } 

    private void drawOtherBottomRightRoundRect(Canvas canvas, Paint paint, float right, 
               float bottom) { 
     canvas.drawRoundRect(new RectF(mMargin, mMargin, right, mMargin + mDiameter), mRadius, mRadius, 
       paint); 
     canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, bottom), mRadius, mRadius, 
       paint); 
     canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint); 
    } 

    private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right, 
                float bottom) { 
     canvas.drawRoundRect(new RectF(mMargin, mMargin, mMargin + mDiameter, mMargin + mDiameter), 
       mRadius, mRadius, paint); 
     canvas.drawRoundRect(new RectF(right - mDiameter, bottom - mDiameter, right, bottom), mRadius, 
       mRadius, paint); 
     canvas.drawRect(new RectF(mMargin, mMargin + mRadius, right - mDiameter, bottom), paint); 
     canvas.drawRect(new RectF(mMargin + mDiameter, mMargin, right, bottom - mRadius), paint); 
    } 

    private void drawDiagonalFromTopRightRoundRect(Canvas canvas, Paint paint, float right, 
                float bottom) { 
     canvas.drawRoundRect(new RectF(right - mDiameter, mMargin, right, mMargin + mDiameter), mRadius, 
       mRadius, paint); 
     canvas.drawRoundRect(new RectF(mMargin, bottom - mDiameter, mMargin + mDiameter, bottom), 
       mRadius, mRadius, paint); 
     canvas.drawRect(new RectF(mMargin, mMargin, right - mRadius, bottom - mRadius), paint); 
     canvas.drawRect(new RectF(mMargin + mRadius, mMargin + mRadius, right, bottom), paint); 
    } 

    @Override public String getId() { 
     return "RoundedTransformation(radius=" + mRadius + ", margin=" + mMargin + ", diameter=" 
       + mDiameter + ", cornerType=" + mCornerType.name() + ")"; 
    } 
} 
1

このギャップは、事前ロリポップデバイスでCardView内部パディングの結果です。 Api < 21では、シャドウとクリッピングのネイティブサポートがないので、CardView代替ソリューションを使用してこれらの効果を再現します。 cardCornerRadiusを定義した場合、プレロリポップデバイスでCardViewはコンテンツのコーナーが重ならないようにコンテンツの埋め込み(コーナー半径の値と等しい)をコンテンツに適用します。この動作を無効にするには

、あなたはXMLで行うことができます。

card_view:cardPreventCornerOverlap="false" 

またはJavaを使用して:

cardView.setPreventCornerOverlap(false) 

を重複コーナーパディングを無効にします。

更新:あなたが本当にあなた自身がこの1のようなライブラリを使用して画像をクリップしようとすることができる前ロリポップデバイスで同じ効果を達成したい場合:

https://github.com/vinc3m1/RoundedImageView

、そうするとき、あなたのコンテンツを問題は前ロリポップデバイスで実行短くないので、私たちはCUSでき

+0

それを修正する解決策の周りの作品はありますか? –

+0

回答が更新されました。この機能が動作するかどうかお知らせください。 –

+0

私は既にcardviewのcard_view:cardPreventCornerOverlap = "false"の中にこれを使用しています。それは私に新しい問題を与えます: - 画像は角がない矩形で表示されます(全画像の終わりにはアーク型) –

関連する問題