Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i give padding to my image #267

Closed
yogeshpaliyal opened this issue May 3, 2018 · 7 comments
Closed

How can i give padding to my image #267

yogeshpaliyal opened this issue May 3, 2018 · 7 comments

Comments

@yogeshpaliyal
Copy link

please review

@hdodenhof
Copy link
Owner

In the same way as with any other View: using padding XML attributes or setPadding methods.

@srujanb
Copy link

srujanb commented Jun 13, 2018

@hdodenhof Actually the usual padding is not working as expected. My image was getting clipped because of the circular shape. I tried padding/margin etc but it is actually adding padding to the entire image view making it impossible to prevent your image getting clipped. If there arn't any workarounds for that, I might have to use alternate options for my circular imageview requirements.

@hdodenhof
Copy link
Owner

@srujanb I'm not sure what exactly you want to achieve but the whole point of this library is to efficiently clip an image to a circle. If you don't want the image to be clipped at all, you don't really need this.

@camrongiuliani
Copy link

@hdodenhof I believe that @srujanb is trying to achieve the same thing I am.

This is what I want (prototype render):

screen shot 2018-06-28 at 12 51 03 pm

And this is what I am getting with this library:
screen shot 2018-06-28 at 12 53 35 pm

Notice how my image (a calendar icon) has no padding around it. Due to this being CENTER_CROP, it would be nice to be able to pad the images.

Would this be possible?

Thanks for this library!

@hdodenhof
Copy link
Owner

hdodenhof commented Jun 29, 2018

@camrongiuliani using this library for what you want to achieve would be very inefficient (and is currently impossible).

As you don't want to crop your image at all, I'd go with the following approach:

  1. Define a ShapeDrawable in res/drawable, e.g. oval.xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <stroke
        android:width="1dp"
        android:color="#FFFFFF"/>
</shape>
  1. Use that shape drawable as a background for a regular image view and give it some padding:
<ImageView
    android:layout_width="160dp"
    android:layout_height="160dp"
    android:padding="48dp"
    android:src="@drawable/calendar" 
    android:background="@drawable/oval"/>

Another approach would be using a LayerDrawable with the circle shape on the bottom layer and your icon above.

@camrongiuliani
Copy link

@hdodenhof thank you for the hasty response, and providing a better solution for my use case!

@Aditya7521
Copy link

You can use

app:civ_border_color="@color/white"
app:civ_border_width="5dp"

to make it look like a padding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants