Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageButton elevation issue

Good afternoon, I am trying to create en ImageButton with a shadow.

To do that :

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:padding="5sp">

    <ImageButton
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/circle_shape_little"
        android:src="@drawable/ic_keyboard_arrow_right_black_24dp"
        android:elevation="3sp"/>
</LinearLayout>

But here is the result :

enter image description here

As you can see, the borders are "cut", and I do not know why.

Does anyone can help me ? Thank you.

like image 666
D. Math Avatar asked Apr 09 '26 23:04

D. Math


1 Answers

Add a layout_margin to your ImageButton. The elevation shadow gets clipped to the margins of the View (which defaults to zero):

<ImageButton
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:layout_margin="5dp"
    android:background="@drawable/circle_shape_little"
    android:src="@drawable/ic_keyboard_arrow_right_black_24dp"
    android:elevation="3dp"/>

Alternatively, you could set the padding of the view and set clipToPadding="false", but this could lead to unexpected results depending on your layout.

Lastly, you should be using dp for everything but textSize, in which case you would use sp.

like image 130
Bryan Avatar answered Apr 11 '26 13:04

Bryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!