Reputation: 318
Even after setting the source to my circulerView it is not showing any image, but when I use simple ImageView it works fine. I have cardview and constrainLayout on it and I'm trying to put my CirculerImageView on it. Also when I set background it shows the image but in square form. Why my CirculerView is not working? Should I create a new raw ring shape file?
Please help me.
my .xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/constrain_layout"
android:orientation="vertical">
<androidx.cardview.widget.CardView
android:id="@+id/driverInfo"
android:layout_width="335dp"
android:layout_height="171dp"
android:layout_marginBottom="8dp"
android:background="@drawable/rectangle"
map:layout_constraintBottom_toBottomOf="@+id/map"
map:layout_constraintEnd_toEndOf="@+id/map"
map:layout_constraintStart_toStartOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imageView2"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:drawingCacheQuality="high"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@drawable/userimage" />
<RatingBar
android:id="@+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="62dp"
android:layout_height="15dp"
android:layout_marginStart="10dp"
android:layout_marginTop="62dp"
android:isIndicator="true"
android:numStars="5"
android:stepSize="0.1"
map:layout_constraintStart_toEndOf="@+id/imageView2"
map:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="38dp"
android:text="Vaibhav"
android:textColor="#323643"
map:layout_constraintStart_toEndOf="@+id/imageView2"
map:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/callDriver"
android:layout_width="111dp"
android:layout_height="38dp"
android:layout_marginStart="62dp"
android:layout_marginTop="37dp"
android:background="@drawable/buttonrect"
android:text="Call Driver"
android:textColor="#FFFFFF"
android:textSize="14sp"
map:layout_constraintStart_toEndOf="@+id/ratingBar"
map:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:layout_constraintBottom_toBottomOf="parent"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintHorizontal_bias="1.0"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toTopOf="parent"
map:layout_constraintVertical_bias="1.0"
tools:context=".HomeActivity" />
<EditText
android:id="@+id/myLocation"
android:layout_width="335dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:background="@drawable/edittextlocation"
android:drawingCacheQuality="high"
android:ems="10"
android:hint="My Location"
android:inputType="textPersonName"
android:paddingStart="40dp"
android:textSize="14sp"
android:viewportWidth="335"
android:viewportHeight="48"
map:layout_constraintEnd_toEndOf="@+id/map"
map:layout_constraintStart_toStartOf="@+id/map"
map:layout_constraintTop_toBottomOf="@+id/appBarLayout" />
<EditText
android:id="@+id/destination"
android:layout_width="335dp"
android:layout_height="48dp"
android:background="@drawable/destination"
android:drawingCacheQuality="high"
android:ems="10"
android:hint="Destination Please! ?"
android:inputType="textPersonName"
android:paddingStart="40dp"
android:textSize="14sp"
map:layout_constraintEnd_toEndOf="@+id/map"
map:layout_constraintStart_toStartOf="@+id/map"
map:layout_constraintTop_toBottomOf="@+id/myLocation" />
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="101dp"
android:layout_height="22dp"
android:layout_gravity="center"
android:textColor="#323643"
android:textSize="18dp" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Upvotes: 2
Views: 2936
Reputation: 7203
Try this code in java file do not need to use external library for make circle image view
Glide.with(context)
.load(url)
.apply(RequestOptions.circleCropTransform())
.into(imageView);
Upvotes: 2
Reputation: 25
Try using normal ImageView and change the shape dynamically using the below code.
profile = new ImageView(ProfileActivity.this);
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.avatar);
Bitmap circularBitmap = ImageConverter.getRoundedCroppedBitmap(bitmap, 100);
profile.setImageBitmap(circularBitmap);
Upvotes: 1
Reputation: 1445
Just replace-:
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imageView2"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:drawingCacheQuality="high"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@drawable/userimage" />
with-:
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imageView2"
android:layout_width="52dp"
android:layout_height="52dp"
android:layout_marginStart="20dp"
android:layout_marginTop="30dp"
android:drawingCacheQuality="high"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toTopOf="parent"
android:src="@drawable/userimage" />
android:src="@drawable/userimage"
Upvotes: 1