Reputation: 427
I'm trying to make my image circular(NOTE: not trying to make ImageView circular but the Image) and fill it with a background color. my fragment code:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootview = inflater.inflate(R.layout.activity_profile, container, false);
ImageView mView = (ImageView) rootview.findViewById(R.id.dp);
RoundedBitmapDrawable im = RoundedBitmapDrawableFactory.create(getActivity().getResources(), BitmapFactory.decodeResource(getActivity().getResources(), R.drawable.my_image));
im.setCircular(true);
im.setColorFilter(ContextCompat.getColor(getContext(), R.color.colorAccent), PorterDuff.Mode.DST_OVER);
mView.setImageDrawable(im);
return rootview;
}
all I get is a non-circular image with no background color on running the app.
EDIT:I achieved the results using
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/profile"
app:civ_border_width="2dp"
app:civ_border_color="#FF000000"/>
But I still want to know why the first code did not work.
EDIT :
I also tried im.setCornerRadius(Math.max(src.getWidth(), src.getHeight()) / 2.0f);
but to no avail
EDIT 2:
I was using Glide(and I really feel stupid for leaving out this information from the question) to display images from firebase storage and it turns out that images from glide are not bit-drawable but transition-drawable and thats why the code did not work
Upvotes: 2
Views: 281
Reputation: 427
I was using Glide(and I really feel stupid for leaving out this information from the question) to display images from firebase storage and it turns out that images from glide are not bit-drawable but transition-drawable and thats why the code did not work
Upvotes: 0
Reputation: 402
You can use drawable to make your ImageView
circular. Create new xml file in drawable folder.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="@color/myColor">
</solid>
</shape>
And implement your color in color.xml
<color name="myColor">#ffffff</color>
Finally set background to your ImageView
Hope it helps.
Upvotes: 1