Comments (15)
mind opening this in a pull request?
from roundedimageview.
I'm still seeing this bug, or a slightly different bug. When I use the following XML, the white border causes the image itself to not be centred within the border circle: it's moved down and to the right by the looks of it. In our case this makes the border feature unusable, which is a shame.
<com.makeramen.roundedimageview.RoundedImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/profile_avatar_default"
android:scaleType="centerCrop"
app:riv_oval="false"
app:riv_corner_radius="30dp"
app:riv_border_width="3dp"
app:riv_border_color="@color/white"/>
from roundedimageview.
A little experimentation shows that this would work, where we simply add /2 after each mBorderWidth, to ensure the image is centred within the border:
mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth/2, (int) (dy + 0.5f) + mBorderWidth/2);
An alternative approach would be to scale the image down a bit (by border width presumably), so the border doesn't overlap its edges at all.
from roundedimageview.
I actually think borderWidth should not be part of the postTransate at all in this case since mBorderRect is already inset by the necessary amount. I think I will just remove that.
There will still needs to be overlap, which is needed for a clean line between the border and the image. Otherwise you see small bits of white between the border and the image due to antialiasing.
from roundedimageview.
Here's a test with super thick and transparent borders.
from roundedimageview.
Hmmm - for me this fix doesn't work correctly, but my suggestion with mBorderWidth/2 does. Maybe there's something screwy with my images, but I don't believe so. I'm using avatar images, that by default are a centred, symmetrical graphic (e.g. the Twitter egg in this example) but I can see that the image does not end up centred within the border with the current fix.
from roundedimageview.
Hm, that looks to be off more than borderwidth/2... Any chance you can provide some sample code to reproduce?
from roundedimageview.
If I add in + mBorderWidth/2 to the translation it appears to centre perfectly.
The XML in question is as follows:
<com.makeramen.roundedimageview.RoundedImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/avatar_image"
android:layout_width="60dp"
android:layout_height="60dp"
app:riv_corner_radius="30dp"
android:layout_gravity="center"
android:layout_marginTop="15dp"
style="@style/BigAvatarWithBorder"/>
A whole canned example would take a bit of effort as the images are fetched from the network etc.
from roundedimageview.
Do you have a copy of the image I could play with?
from roundedimageview.
Here's an example of one of the default Twitter avatars, where the egg is perfectly centred within the image: https://abs.twimg.com/sticky/default_profile_images/default_profile_2_normal.png
from roundedimageview.
Is there a workaround for this issue?
from roundedimageview.
For now I have my own versions of RoundedImageView and RoundedDrawable which I use in preference to the ones in the library, so that I can apply the fix (at least the fix that works for me, as detailed above).
The fixed code is in my RoundedDrawable, but you need RoundedImageView too, so that it uses the modified RoundedDrawable throughout.
from roundedimageview.
I have implemented your solution but the image is not centred when scale type is centre.
This happens only for some images.
Sample 1 image is not centred.
Link to modified file
https://gist.github.com/aftabsikander/2a9a994e9d721cb4a36d
Edited:
The XML is as follows:
<com.test.RoundedImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/avatar_image"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center"
android:scaleType="center"
android:src="@drawable/test1"
app:riv_border_color="@color/colorPrimary"
app:riv_border_width="2dp"
app:riv_corner_radius="180dp"
app:riv_oval="true" />
from roundedimageview.
news on this?
from roundedimageview.
After taking a second look, looks like @alwaysthecritic had the right fix the whole time. Not sure why that didn't click the first time.
from roundedimageview.
Related Issues (20)
- convert drawble image to bitmap HOT 1
- How can I display a gif??? HOT 2
- Fatal Exception: java.lang.OutOfMemoryError HOT 2
- TransitionDrawable support
- Out of Memory Error in resolveBackgroundResource HOT 1
- ImageView on top of roundedimageview HOT 1
- Losing Fade-in Animation when used with Picasso HOT 1
- <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" /> HOT 1
- Could not resolve com.makeramen:roundedimageview:2.3.0.
- RoundedImageView设置ScaleType=ScaleType.FIT_XY时,图片显示不出的效果,没有进行拉伸。用ImageView是正常的。
- RoundedImageView not working Glide transition animation and rounded corner broken! HOT 1
- LinearLayout使用layout_weight属性的bug HOT 1
- Display error when layout change caused by screen rotation
- android:scaleType Not working in new version HOT 3
- cannot show gif HOT 1
- Conflict with Glide .transition(DrawableTransitionOptions.withCrossFade) HOT 2
- Fatal Exception: java.lang.OutOfMemoryError HOT 1
- 控件设置android:tint 属性对图片着色没有效果
- cannot show gif. How can I fix that? HOT 3
- Will your library supprot OpenHarmony platform by JavaScript language? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from roundedimageview.