kam773
kam773

Reputation: 83

circular image view attributes not found

I'm trying to build a circular image view but when I build the project there is an error occurring with some of the attributes:

gradle console error

I don't know how to solve it. Maybe it's a lack of some additional libraries in build.gradle? My layout code is shown below:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="pl.educativo.diagonalcutview.MainActivity">

    <RelativeLayout
        android:id="@+id/background"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:background="@drawable/activity_background" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/background"
        android:layout_marginStart="20dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="-100dp">

        <ImageView
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:src="@drawable/bebe2"
            android:civ_border="true"
            android:civ_border_color="@color/semiTransparentWhite"
            android:civ_border_width="10dp"
            android:contentDescription="TODO" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginStart="12dp"
            android:layout_marginEnd="12dp"
            android:layout_marginBottom="24dp"
            android:layout_gravity="bottom">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="sans-serif-light"
                android:text="@string/bebe_rexha"
                android:textSize="30sp"
                android:textColor="@android:color/black"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="sans-serif-light"
                android:text="musician, singer, songwriter"
                android:textSize="14sp"/>
        </LinearLayout>
    </LinearLayout>

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/actionBarSize"
        android:layout_marginTop="24dp"
        app:theme="@style/TransparentBar">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="sans-serif-light"
            android:gravity="center_vertical"
            android:text="About"
            android:textSize="24sp" />
    </android.support.v7.widget.Toolbar>
</RelativeLayout>

Upvotes: 0

Views: 5235

Answers (5)

Arpit Prajapati
Arpit Prajapati

Reputation: 365

add compile 'com.mikhaellopez:circularimageview:3.0.2' to you gradle and use Lopez Mikhael's CircularImageView (code snippet from the project readme)

<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"/>

instead of ImageView

Upvotes: 2

Preetam Pal
Preetam Pal

Reputation: 256

You can use ShapeableImageView for circular image. Its very easy to use. It comes in the Material Components Library. In your layout, place this ShapeableImageView.

 <com.google.android.material.imageview.ShapeableImageView
  android:id="@+id/image_view"
  app:srcCompat="@drawable/..." />

For circular image, add an attribute- shapeAppearanceOverlay in the ShapeableImageView.

   <com.google.android.material.imageview.ShapeableImageView
   android:id="@+id/image_view"
   app:shapeAppearanceOverlay="@style/circleImageView"
   app:srcCompat="@drawable/..." />

And in your styles.xml, add this style circleImageView.

   <style name="circleImageView" parent="">
   <item name="cornerFamily">rounded</item>
   <item name="cornerSize">50%</item>
   </style>

Upvotes: 0

Abdur Rahman
Abdur Rahman

Reputation: 1001

Use this Library in App level build.gradle file

implementation 'de.hdodenhof:circleimageview:2.1.0'

Its would be used like this

<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/img_user"
    android:layout_width="150sp"
    android:layout_height="150sp"
    android:layout_centerHorizontal="true"
    android:src="@drawable/ic_driver"
    app:civ_border_color="@color/colorWhite"
    app:civ_border_width="2dp"
    app:civ_fill_color="@color/colorWhite20" />

It has many more other attributes you can check them on:

https://github.com/hdodenhof/CircleImageView

Upvotes: 5

add this implementation to your build.gradle(app)

//circle image view
    implementation 'de.hdodenhof:circleimageview:3.1.0'


//image  and load  from database
   implementation 'com.squareup.picasso:picasso:2.71828

'

Upvotes: 0

Mohammad Tabbara
Mohammad Tabbara

Reputation: 1467

First of all I doubt there is an Attribute civ_(Something) in ImageView as my Knowledge goes. But it you were trying to use:

https://github.com/hdodenhof/CircleImageView

Then the Code should be like:

<de.hdodenhof.circleimageview.CircleImageView
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:src="@drawable/bebe2"
    app:civ_border_color="@color/semiTransparentWhite"
    app:civ_border_width="10dp"
    android:contentDescription="TODO"/>

But you will need to use(In Gradle file):

dependencies {
    ...
    implementation 'de.hdodenhof:circleimageview:2.2.0'
}

Upvotes: 3

Related Questions