RoundedImageView

repository·main·Indexed 27 days ago

https://github.com/vinc3m1/roundedimageview

A high-performance Android ImageView and Drawable supporting rounded corners, ovals, and borders without bitmap copies or unaccelerated clipping. Version 2.3.0 provides XML attributes and Java methods for configuration, as well as a RoundedTransformationBuilder for Picasso. Note: This project is archived; users are encouraged to use AndroidX RoundedBitmapDrawable or library-specific transformations from Glide or Picasso instead.

Tokens
1.3K
Snippets
4
Records
6
Agent score
42%

What's inside RoundedImageView

  1. Use recommended alternatives for image rounding

    main

    Note: RoundedImageView is archived and no longer actively maintained.

    For modern Android development, the following alternatives are recommended:

    1. For Bitmaps bundled in your APK: Use androidx.core.graphics.drawable.RoundedBitmapDrawable. It is more efficient and decouples the Drawable from the ImageView.
    2. For images loaded from network or disk: Use transformation libraries compatible with your image loader:
    3. For Vector Drawables: Modify the vector or drawable directly to include rounding for optimal performance.

    Avoid using RoundedImageView with Glide transforms, as they are not supported.

  2. Install RoundedImageView via Gradle

    main

    To use RoundedImageView, add mavenCentral() to your repositories and include the dependency in your build.gradle file.

    Dependency: com.makeramen:roundedimageview:2.3.0

    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation 'com.makeramen:roundedimageview:2.3.0'
    }
  3. Known issues and limitations of RoundedImageView

    main

    When using RoundedImageView, be aware of the following limitations:

    • VectorDrawables: Not supported. The library is designed for BitmapDrawables only. Using other drawables may cause high memory usage or failure.
    • ColorDrawables: Poorly supported. It is recommended to use rounded VectorDrawables instead to reduce memory pressure.
    • Glide Integration: Glide transforms are not supported. Use wasabeef/glide-transformations for rounding images loaded via Glide.
  4. Configure RoundedImageView in XML

    main

    You can define a RoundedImageView in your layout XML files using the app:riv_* namespace for custom attributes.

    Supported attributes:

    • app:riv_corner_radius: Corner radius in dp.
    • app:riv_border_width: Border width in dp.
    • app:riv_border_color: Border color.
    • app:riv_mutate_background: Whether to mutate the background.
    • app:riv_tile_mode: Tile mode for repeating drawables (e.g., repeat).
    • app:riv_oval: Set to true to make the view an oval/circle.
    <com.makeramen.roundedimageview.RoundedImageView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/imageView1"
            android:src="@drawable/photo1"
            android:scaleType="fitCenter"
            app:riv_corner_radius="30dip"
            app:riv_border_width="2dip"
            app:riv_border_color="#333333"
            app:riv_mutate_background="true"
            app:riv_tile_mode="repeat"
            app:riv_oval="true" />
  5. Create a Picasso Transformation with RoundedTransformationBuilder

    main

    Use RoundedTransformationBuilder to create a Transformation object for Picasso. This allows you to apply rounded corners and borders during the Picasso loading pipeline.

    Supported builder methods:

    • borderColor(int)
    • borderWidthDp(int)
    • cornerRadiusDp(int)
    • oval(boolean)
    Transformation transformation = new RoundedTransformationBuilder()
              .borderColor(Color.BLACK)
              .borderWidthDp(3)
              .cornerRadiusDp(30)
              .oval(false)
              .build();
    
    Picasso.with(context)
        .load(url)
        .fit()
        .transform(transformation)
        .into(imageView);
  6. Configure RoundedImageView in Java

    main

    You can programmatically configure a RoundedImageView using its setter methods.

    Key methods:

    • setScaleType(ScaleType)
    • setCornerRadius(float)
    • setBorderWidth(float)
    • setBorderColor(int)
    • mutateBackground(boolean)
    • setOval(boolean)
    • setTileModeX(Shader.TileMode)
    • setTileModeY(Shader.TileMode)
    RoundedImageView riv = new RoundedImageView(context);
    riv.setScaleType(ScaleType.CENTER_CROP);
    riv.setCornerRadius((float) 10);
    riv.setBorderWidth((float) 2);
    riv.setBorderColor(Color.DKGRAY);
    riv.mutateBackground(true);
    riv.setImageDrawable(drawable);
    riv.setBackground(backgroundDrawable);
    riv.setOval(true);
    riv.setTileModeX(Shader.TileMode.REPEAT);
    riv.setTileModeY(Shader.TileMode.REPEAT);