this answer을 기반으로 한 둥근 이미지 뷰를 만들었습니다. 완벽하게 이미지를 만듭니다. 그러나 두 가지 문제점이 있습니다.왜 imageView 라운드의 배경이 어둡습니까?
- 이 이미지는 내가 왜 아무 생각이 없다 90도 회전
- 이미지가 나는 아무 생각에서 온다 가지고 어두운 배경을 가지고 (사용자가 버튼을 클릭, 사용자의 갤러리가 표시되면 사용자는 자신의 프로필 그림으로 이미지를 선택) 어디에.
내가 사용 클래스 :
public class RoundImageView extends ImageView {
private Path path;
private Paint paint;
private PorterDuffXfermode porterDuffXfermode;
public RoundImageView(Context context) {
super(context);
init();
}
public RoundImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public RoundImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
setWillNotDraw(false);
path = new Path();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
porterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_IN);
}
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.TRANSPARENT);
// Create a circular path.
final float halfWidth = canvas.getWidth()/2;
final float halfHeight = canvas.getHeight()/2;
final float radius = Math.max(halfWidth, halfHeight);
path.addCircle(halfWidth, halfHeight, radius, Path.Direction.CCW);
paint.setXfermode(porterDuffXfermode);
canvas.drawPath(path, paint);
}
}
방법 내가 레이아웃을 추가 해요 :
<com.allstarxi.widget.RoundImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/ic_launcher"
android:id="@+id/imageView"
android:contentDescription="@string/general_content_description"
android:scaleType="center" />
이것은을 스크린 샷 :
Hesam을 초래합니다하지 않을 경우, AsynTask을 사용하여로드해야하는 경우, 당신의 코드를 얻을 \t \t \t mTopCard.setLayerType (널 LAYER_TYPE_HARDWARE)를 넣어; init() 메서드 안에 있고 나를 위해 작동합니다. 또한 매니페스트에 하드웨어 가속 플래그 "true"가 있습니다. – Marabita