logo
down
shadow

ImageView hides the round corners of the parent


ImageView hides the round corners of the parent

Content Index :

ImageView hides the round corners of the parent
Tag : java , By : user96271
Date : January 11 2021, 05:14 PM

will help you You can put the ImageView inside a CardView and it should keep the corners round. I am not sure if it's the best way to go about it but it works.

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to I round the corners of ImageView for only on side fit to the parent layout in Android?


Tag : android , By : Bo.
Date : March 29 2020, 07:55 AM
Hope this helps I think that you should apply a transformation when loading the images. For example if you use picasso for loading imageas you could apply this transformation:
Base class:
public class RoundedCornersBitmap implements Transformation {

private static final float DEFAULT_RADIUS = 5.f;
private static final int DEFAULT_BORDER_COLOR = Color.WHITE;
private static final int DEFAULT_STROKE_WIDTH = 3;

protected float mCornerRadius;
protected int mBorderColor;
protected int mStrokeWidth;

@Override
public String key() {
    return "roundedCorners()";
}

public RoundedCornersBitmap() {
    mCornerRadius = DEFAULT_RADIUS;
    mBorderColor = DEFAULT_BORDER_COLOR;
    mStrokeWidth = DEFAULT_STROKE_WIDTH;
}

public RoundedCornersBitmap(float cornderRadius, int borderColor, int strokeWidth) {
    mCornerRadius = cornderRadius;
    mBorderColor = borderColor;
    mStrokeWidth = strokeWidth;
}

@Override
public Bitmap transform(Bitmap bitmap) {
    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final Paint paint = new Paint();
    final Rect rect = new Rect(mStrokeWidth, mStrokeWidth, (bitmap.getWidth() - mStrokeWidth), bitmap.getHeight()
            - mStrokeWidth);
    final RectF rectF = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());

    paint.setAntiAlias(true);
    paint.setColor(mBorderColor);
    paint.setStrokeWidth(3);

    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawRoundRect(rectF, mCornerRadius, mCornerRadius, paint);
    //canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth() / 2, paint);

    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(bitmap, rect, rect, paint);
    bitmap.recycle();
    return output;
}

/**
 * @return the mCornerRadius
 */
public float getCornerRadius() {
    return mCornerRadius;
}

/**
 * @param mCornerRadius
 *            the mCornerRadius to set
 */
public void setCornerRadius(float mCornerRadius) {
    this.mCornerRadius = mCornerRadius;
}

/**
 * @return the mBorderColor
 */
public int getBorderColor() {
    return mBorderColor;
}

/**
 * @param mBorderColor
 *            the mBorderColor to set
 */
public void setBorderColor(int mBorderColor) {
    this.mBorderColor = mBorderColor;
}

/**
 * @return the mStrokeWidth
 */
public int getStrokeWidth() {
    return mStrokeWidth;
}

/**
 * @param mStrokeWidth
 *            the mStrokeWidth to set
 */
public void setStrokeWidth(int mStrokeWidth) {
    this.mStrokeWidth = mStrokeWidth;
}

}
public class LeftRoundedCornersBitmap extends RoundedCornersBitmap {

    public LeftRoundedCornersBitmap() {
        super();
    }

    public LeftRoundedCornersBitmap(float cornderRadius, int borderColor, int strokeWidth) {
        super(cornderRadius, borderColor, strokeWidth);
    }

    @Override
    public Bitmap transform(Bitmap bitmap) {
        Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(output);

       final Paint paint = new Paint();
       final Rect rect = new Rect(mStrokeWidth, mStrokeWidth, (bitmap.getWidth() - mStrokeWidth), bitmap.getHeight()
            - mStrokeWidth);
       final RectF rectF = new RectF(rect);
       final Rect topRightRect = new Rect(bitmap.getWidth() / 2, 0, bitmap.getWidth(), bitmap.getHeight() / 2);
       final Rect bottomRect = new Rect(bitmap.getWidth() / 2, bitmap.getHeight() / 2, bitmap.getWidth(), bitmap.getHeight());

       paint.setAntiAlias(true);
       paint.setColor(mBorderColor);
       paint.setStrokeWidth(3);

       canvas.drawARGB(0, 0, 0, 0);
       canvas.drawRoundRect(rectF, mCornerRadius, mCornerRadius, paint);
       canvas.drawRect(topRightRect, paint);
       canvas.drawRect(bottomRect, paint);

       paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
       canvas.drawBitmap(bitmap, rect, rect, paint);
       bitmap.recycle();
       return output;
   }
}
compile 'com.squareup.picasso:picasso:2.5.2'
Picasso.with(context).load(imageUrl).transform(new LeftRoundedCornersBitmap()).into(youImageView);

Border radius 50% on parent doesn't round corners


Tag : html , By : Nulq
Date : March 29 2020, 07:55 AM
Any of those help So I have found an answer to this that is quite dirty, but is working for what I need it for...
The original issue seemed to only affect mobile devices, specifically Android Chrome. For some reason, the image would hide itself in the browser if the image was smaller than 60 pixels, not sure how or why this happens but my work around is below:
.profile-img__wrapper {
    border: 2px solid #d0d0d0;
    width: 30px;
    height: 30px;
    display: block;
    border-radius: 50%;
    overflow: hidden;
    -moz-box-sizing: content-box;
    -webkit-box-sizing: content-box;
    box-sizing: content-box;
}

.profile-img {
    width: 30px;
    height: 30px;
    background-size: cover;
    display: block;
    background-position: 50% 0; 
}

<span class="profile-img__wrapper">
    <span class="profile-img" style="background-image: url('imageSource')"></span>
</span>

Imageview round corners and mask shape via xml do not work in AS 3.0


Tag : android , By : DK.
Date : March 29 2020, 07:55 AM
Hope this helps Topics checked before creating topic , Final solution via java only (original idea proposed by @pskink)
    ImageView img = (ImageView) findViewById(R.id.img);
    Bitmap src1 = BitmapFactory.decodeResource(getResources(), R.drawable.img_port);
    RoundedBitmapDrawable dr1 = RoundedBitmapDrawableFactory.create(getResources(), src1);
    dr1.setCornerRadius(Math.max(src1.getWidth(), src1.getHeight()) / 10f);
    img.setImageDrawable(dr1);
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="15dp"  />
    <solid/>
</shape>

Why is making two corners round slower than make all corners round?


Tag : ios , By : Julian Ivanov
Date : March 29 2020, 07:55 AM

android unable to round the corners of imageview?


Tag : android , By : Hugo
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • How to avoid casting with generic return values?
  • Java/RegEx - Negation of pattern not working
  • How to split a string to non empty words if it might include a separator like tab on first place
  • Supplier<Sequence<String>> cannot be iterated more than once
  • Why there is only one thread can actually started in @PostConstruct method?
  • Manage CompletionStage inside of Netty handler
  • Url Problem while Developing on Localhost and deploy on Remote Virtual Server
  • How to identify the missing type id in Jackson error?
  • android data binding error: cannot find symbol
  • Spring Boot application with a jar dependency does not run after maven build
  • Spring Data JPA query , filter ? search engine ? JPQL?
  • Why LiveData returns null in ViewModel?
  • what this line of code mean....new URLClassLoader(new URL[0],getClass().getClassLoader());
  • Why do need to use new Random() instead of just Random Randomnum?
  • I want to access zk components from the java file
  • How do I cast FieldValue.serverTimestamp() to Kotlin/Java Date Class
  • Insertion Sort Double Array with User Input - JAVA
  • Creating 2 dimesional array with user input and find sum of specific columns
  • can not get Advertising ID Provider in android
  • Convert list of Objects to map of properties
  • How to represent an undirected weighted graph in java
  • Return values as array from collection
  • ByteBuddy generic method return cast to concrete type
  • Is there a way to find setter method by its getter method or vice versa in a class?
  • Get aggregated list of properties from list of Objects(Java 8)
  • Unable to find a document in Mongodb where exact date match in java
  • UsernamePasswordAuthenticationFilter skips success handler
  • Use Java filter on stream with in a stream filter
  • Default Login not successful in spring boot 2.1.7
  • Adding key value pairs from a file to a Hashmap
  • Rub regex: matching a char except when after by another char
  • Convert Base64 String to String Array
  • Escape Unicode Character 'POPCORN' to HTML Entity
  • An empty JSON field which is a boolean/nullable field in Java model, is getting converted as null
  • Mongo java driver cannot find public constructor for interface
  • How to unit test writing a file to AWS Lambda output stream?
  • How to make a GitHub GraphQL API Call from Java
  • What's the difference between @ComponentScan and @Bean in a context configuration?
  • Expected class or package adding a view using a class
  • can be delete of a element in a static array be O(1)?
  • Instance variable heap or stack ? ( with specific example)
  • Assert progress of ProgressBar in Espresso test
  • How to detect if gson.fromjson() has excess elements
  • I cant generate the proper code to select the a specific filter on a BI dashboard I am working on
  • How to Inject Dependencies into a Servlet Filter with Spring Boot Filter Registration Bean?
  • Thrift types as a Generic
  • Effective algorithm to random 4 unique integers less than a big max such as 100_000
  • Combining or and negation in Java regex?
  • Unable to instantiate default tuplizer Exception
  • Multi-tenant migration to work with quarkus
  • Ignite persisting a Set: Cannot find metadata for object with compact footer
  • Maven cannot resolve Jacob dependency using eclipse
  • testcontainers oracle database container starts before database user is created
  • Launching two spring boot apps in integration test
  • Is there a way to add a HashMap's value that is a integer array into a ArrayList?
  • Is there any way that I can get a parameter in paintComponent?
  • Empty stack with one recursive method and one iterative method
  • What's the behavior of onBackpressureBuffer in RxJava2
  • Java regex can only use 1 quantifier in a lookback (need 2)
  • How to fix error in native query : it is showing syntax error near or at
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com