2017-05-11 2 views
0

スケールされた画像(CenterCrop)を右上と右下(右下)から丸くするにはどうすればいいですか?右側からスケールされたImageViewを丸めただけです

Sampleこれは私がやろうとしていることです。

似たようなことができるクラス(TopRoundedImage、作者のおかげで)が、左上と右上に見つかりました。私はそれを変更しようとしているが、私はまだ間違っていると思う。

また、グライドを使用してインターネットから画像を要求していますが、右側を丸くしたいと考えています。

バックグラウンド描画可能ですが、動作しません。

public class RightRoundedImageView extends AppCompatImageView 
{ 
    private final RectF roundRect = new RectF(); 
    private float rect_radius = 7; 
    private final Paint maskPaint = new Paint(); 
    private final Paint zonePaint = new Paint(); 

    public RightRoundedImageView(Context context, AttributeSet attrs) 
    { 
     super(context, attrs); 
     init(); 
    } 

    public RightRoundedImageView(Context context) 
    { 
     super(context); 
     init(); 
    } 

    private void init() 
    { 
     maskPaint.setAntiAlias(true); 
     maskPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); 
     zonePaint.setAntiAlias(true); 
     zonePaint.setColor(Color.WHITE); 
     float density = getResources().getDisplayMetrics().density; 
     rect_radius = rect_radius * density; 
    } 

    public void setRectAdius(float radius) 
    { 
     rect_radius = radius; 
     invalidate(); 
    } 

    @Override 
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) 
    { 
     super.onLayout(changed, left, top, right, bottom); 
     int w = getWidth(); 
     int h = getHeight(); 
//  roundRect.set(0, 0, w, h + rect_radius);//round top 
     roundRect.set(0, 0, w + rect_radius, h); //round left 
//  roundRect.set(0, 0, w - rect_radius, h); //round all 


    } 

    @Override 
    public void draw(Canvas canvas) 
    { 
     canvas.saveLayer(roundRect, zonePaint, Canvas.ALL_SAVE_FLAG); 
     canvas.drawRoundRect(roundRect, rect_radius, rect_radius, zonePaint); 
     canvas.saveLayer(roundRect, maskPaint, Canvas.ALL_SAVE_FLAG); 
     super.draw(canvas); 
     canvas.restore(); 
    } 

} 

誰でも知っている、または助けていただければ幸いです。ありがとう。

+0

をチェックし、あなたが探しているどのようにサンプル画像を投稿することができますか? – Lingeshwaran

+0

@Lingeshwaran画像が –

答えて

0

あなたはこのために描画可能な形状を使用することができます。

<?xml version="1.0" encoding="UTF-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android"> 
     <solid android:color="#FFFFFF"/> 
     <stroke android:width="3dip" android:color="#B1BCBE" /> 
     <corners android:bottomLeftRadius="0dp" android:bottomRightRadius="10dp" 
      android:topLeftRadius="0dp" android:topRightRadius="10dp"/> 
     <padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" /> 
    </shape> 

imageView.setBackground(this.getResources().getDrawable(R.drawable.my_shape)); 

も、このリンク質問how-to-make-an-imageview-with-rounded-corners

+0

であることを確認してください。リンクが動作するので、私のクラスを調整する方法を理解できませんでした。拡大画像を使用している場合は、そのリンクを使用することをおすすめします –

関連する問題