2014-04-16 135 views

回答

0

这个RoundedImageView Library适合我。我刚才设置的圆角半径作为dimens.xml文件的尺寸,并从去那里

<com.makeramen.RoundedImageView 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/imageView1" 
     android:src="@drawable/photo1" 
     android:scaleType="centerCrop" 
     app:corner_radius="@dimen/mycorner_radius_in_dp" 
     app:border_width="2dip" 
     app:border_color="#333333" 
     app:round_background="true" 
     app:is_oval="true" /> 

它不有关的图像尺寸

+0

这是一个很好的库,它解决了我的问题,谢谢! –

0

让您将用打造循环视图的Java文件护理。

public class CircularImageView extends ImageView { 

//you can change the radius to modify the circlur shape into oval or rounded rectangle 

public static float radius = 100.0f; 

public CircularImageView(Context context) { 
super(context); 
} 

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

public CircularImageView(Context context, AttributeSet attrs, int defStyle) { 
super(context, attrs, defStyle); 
} 

@Override 
protected void onDraw(Canvas canvas) { 
Path clipPath = new Path(); 
RectF rect = new RectF(0, 0, this.getWidth(), this.getHeight()); 
clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW); 
canvas.clipPath(clipPath); 
super.onDraw(canvas); 
} 
} 

这种使用在布局这个Java文件中像这样经过:

<com.yourpackagename.CircularImageView 
android:id="@+id/logo_ngo" 
android:layout_width="50dp" 
android:layout_height="50dp" 
android:background="@drawable/circle" 
android:src="@drawable/file_logo" 
android:layout_alignParentTop="true" 
android:layout_alignParentLeft="true" 
android:layout_alignParentStart="true" 
android:contentDescription="@string/content_description" 
android:layout_margin="@dimen/medium_margin" 
android:scaleType="centerCrop"/> 

这里file_logo是镜像文件和圆形的文件名,你将下面的XML使用:

<?xml version="1.0" encoding="utf-8"?> 
<shape 
xmlns:android1="http://schemas.android.com/apk/res/android" 
android1:shape="oval"> 

<stroke android1:width="1dp" 
     android1:color="#000" > 
</stroke> 

<size 
    android1:width="50dp" 
    android1:height="50dp" > 
</size> 

<corners android1:radius="1dp" > 
</corners> 

</shape> 

这为我工作,如果有人有更好的解决方案,请分享你的。

相关问题