在 android 磨损中使用 CircledImageView

Using CircledImageView in android wear

我正在使用 CircledImageViewListView 中显示图像,但我没有将图像视图显示为圆形。谁能告诉我如何做到这一点?

试试这个对我有用的短代码:

RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(Activity.this.getResources(), yourbitmap);
roundedBitmapDrawable.setCircular(true);
your imageview.setImageDrawable(roundedBitmapDrawable);

如果您使用 Glide library 下载图片,您可以这样做。

Glide.with(context).load(your image url).asBitmap().placeholder(your default place holder).error(error place holder).into(new BitmapImageViewTarget(your imageview) {
        @Override
        protected void setResource(Bitmap resource) {
            super.setResource(resource);
            RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(Activity.this.getResources(), resource);
            roundedBitmapDrawable.setCircular(true);
            your imageview.setImageDrawable(roundedBitmapDrawable);
        }
    });

你也可以用Picasso library

做这些事情

通过将高度和宽度设置为环绕内容并提供圆的半径,就可以实现了。

这是适合我的代码。

 <android.support.wearable.view.CircledImageView
        android:id="@+id/im_action_icons"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        app:circle_border_color="#FFFFFFFF"
        app:circle_border_width="2dp"
        app:circle_color="@color/blue"
        app:circle_radius="23dp" />