2017-05-11 5 views
0

오른쪽 상단 및 오른쪽 하단 (모든 오른쪽)에서 크기 조정 된 이미지 (가운데 맞춤) 만 반올림하려면 어떻게해야합니까?오른쪽에서 이미지 크기가 반올림 된

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

을 확인하십시오. 수업을 조정하는 방법을 알 수 없습니다. 크기 조정 된 이미지를 사용하는 경우 해당 링크를 사용하는 것이 좋습니다. –

관련 문제