【问题标题】:Android Piccaso with red circular border around image图像周围带有红色圆形边框的 Android Piccaso
【发布时间】:2017-05-04 03:40:22
【问题描述】:

我正在将 Piccaso 库用于圆形图像,但不知何故我无法在图像周围添加红色圆形边框。我正在使用下面的转换类来做到这一点:

ublic class RedCircleTransform implements Transformation {
        int mBorderSize;

        @Override
        public Bitmap transform(Bitmap source) {
            int size = Math.min(source.getWidth(), source.getHeight());

            int x = (source.getWidth() - size) / 2;
            int y = (source.getHeight() - size) / 2;

            Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
            if (squaredBitmap != source) {
                source.recycle();
            }

            Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);

            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint();
            BitmapShader shader = new BitmapShader(squaredBitmap,
                    BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
            paint.setShader(shader);
        paint.setStrokeWidth(10);
            paint.setColor(Color.RED);
            paint.setAntiAlias(true);

            float r = size / 2f;
            canvas.drawCircle(r, r, r, paint);

            squaredBitmap.recycle();
            return bitmap;
        }

        @Override
        public String key() {
            return "circle";
        }
}

【问题讨论】:

标签: android


【解决方案1】:

您可以通过Lopez Mikhael使用CircularImageView

GRADLE

 compile 'com.mikhaellopez:circularimageview:3.0.2'

XML

<com.mikhaellopez.circularimageview.CircularImageView
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:src="@drawable/image"
        app:civ_border_color="#EEEEEE"
        app:civ_border_width="4dp"
        app:civ_shadow="true"
        app:civ_shadow_radius="10"
        app:civ_shadow_color="#8BC34A"/>

【讨论】:

    【解决方案2】:

    将此依赖项用于圆形图像视图,它还包括其他类型的图像视图。

    将此行添加到您的依赖项中

    compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'
    

    在 XML 中

    <com.github.siyamed.shapeimageview.CircularImageView
            android:id="@+id/android_gridview_image"
            android:layout_width="75dp"
            android:layout_height="65dp"
            app:siBorderColor="#fff"
            android:layout_marginTop="15dp" />
    

    【讨论】:

      猜你喜欢
      • 2016-08-22
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-26
      相关资源
      最近更新 更多