Java 如何在Android联系人应用程序中为收藏夹功能创建圆形图标?
我正在寻找一种方法来实现一个圆形缩略图视图,供用户从联系人列表中选择他们的收藏夹。可以使用自定义列表视图来完成吗?我还希望能够在用户长按缩略图时创建上下文菜单。如果有人也知道这样一个实现的开源资源,那就太棒了,如果不是一个如何实现的伪示例,也可以。谢谢大家! 因为我不能发布图片,这里有一个Java 如何在Android联系人应用程序中为收藏夹功能创建圆形图标?,java,android,Java,Android,我正在寻找一种方法来实现一个圆形缩略图视图,供用户从联系人列表中选择他们的收藏夹。可以使用自定义列表视图来完成吗?我还希望能够在用户长按缩略图时创建上下文菜单。如果有人也知道这样一个实现的开源资源,那就太棒了,如果不是一个如何实现的伪示例,也可以。谢谢大家! 因为我不能发布图片,这里有一个 (来源:)您必须使用外部库 使用这个库 这是您的图像视图 <com.pkmmte.view.CircularImageView android:id="@+id/imgAvatar
(来源:)您必须使用外部库 使用这个库 这是您的图像视图
<com.pkmmte.view.CircularImageView
android:id="@+id/imgAvatar
android:layout_width="250dp"
android:layout_height="250dp"
android:src="@drawable/image"
app:border="true"
app:border_color="#EEEEEE"
app:border_width="4dp"
app:shadow="true" />
用法
创建一个类RoundedImageView,该类将扩展ImageView,然后对其进行自定义。然后将其用作xml中的视图
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.ImageView;
public class RoundedImageView extends ImageView {
public RoundedImageView(Context context) {
super(context);
}
public ChimmerRoundedImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public RoundedImageView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas) {
float radius = 90.0f; // angle of round corners
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);
}
}
并将此属性添加到android清单中的应用程序标记中
<application
android:hardwareAccelerated="false"
/>
imgAvatar = (CircularImageView) findViewById(R.id.imgAvatar);
imgAvatar.setImageResource(your image here);
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.widget.ImageView;
public class RoundedImageView extends ImageView {
public RoundedImageView(Context context) {
super(context);
}
public ChimmerRoundedImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public RoundedImageView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas) {
float radius = 90.0f; // angle of round corners
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);
}
}
<application
android:hardwareAccelerated="false"
/>