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

A workaround to add elevation to CircleImageView and make it more button like #270

Closed
fredliao123 opened this issue May 17, 2018 · 3 comments

Comments

@fredliao123
Copy link

So I need to make the CirleImageView to be more like a button. And I want this view to show some custom or maybe online image. So FloatActionButton won't be a solution.

I referenced to this issue and come up with a solution:

So to have a elevation, we must have a background, this is my background

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <solid android:color="@color/white"/>
</shape>

The background color can't be @android:color/transparent, it will make elevation disappear.
Then set this background to CircleImageView. and set an elevation. But I soon find out that the elevation is partially cut off like this
wrong_cllip

I think that's because the shadow reached the boarder of view
So I added a Layout to wrap around CircleImageView and make it slightly larger than CircleImageView.
So the code looks like this

 <FrameLayout
    android:layout_width="@dimen/logo_wrapper_size"
    android:layout_height="@dimen/logo_wrapper_size"
    android:layout_marginEnd="@dimen/large_margin"
    app:layout_constraintEnd_toEndOf="parent">

    <de.hdodenhof.circleimageview.CircleImageView
      android:id="@+id/logo"
      android:layout_width="@dimen/logo_size"
      android:layout_height="@dimen/logo_size"
      android:layout_gravity="center"
      android:background="@drawable/circle_background"
      android:elevation="@dimen/standard_margin"
      android:foreground="@drawable/round_selector"
      android:onClick='@{() -> clickListener.onItemActionClick(itemViewModel, "")}'
      android:src="@drawable/placeholder_bitmap" />
</FrameLayout>
<dimen name="logo_wrapper_size">78dp</dimen>
<dimen name="logo_size">54dp</dimen>

And this makes CircleImageView have a nice shadow like a FAB. It's even better when I added a ripple animation using this workaround

device-2018-05-17-111412

@hdodenhof
Copy link
Owner

Nice work! Since version 2.2.0 CircleImageView actually comes with native support for elevation, hence it shouldn't be required to add a circle shaped background anymore.

@fredliao123
Copy link
Author

Thank you. I tried version 2.2.0. It does have elevation now. Kudos! A wrapper is still needed or the elevation will be cut off on the edge.

@hdodenhof
Copy link
Owner

A wrapper is still needed or the elevation will be cut off on the edge.

Correct, that's actually also these case for a regular ImageView. I'll close this for now as it's not really an issue with the library that needs to be worked on.

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

2 participants