remove padding from shadow blur on 9 patch image

316 views Asked by At

i've created shadow using this 9 patch generator link because i need the offset, blur, and the round option

https://inloop.github.io/shadow4android/

9 patch shadow image

but it looks like created padding around 9 patch because of the shadow blur so the result when im using the image on android studio look like this layout with 9 patch background

i want my 9 patch become background shadow for my linearlayout without padding around it, how do i achieve this?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingHorizontal="26dp"
    android:paddingVertical="22dp"
    tools:context=".TeamDetailActivity"
    android:id="@+id/profile_container"
    android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/pls"
                android:orientation="vertical">

                    <ImageView
                        android:layout_width="50dp"
                        android:layout_height="wrap_content"
                        android:adjustViewBounds="true"
                        android:scaleType="fitXY"
                        android:src="@drawable/psg" />

            </LinearLayout>

</LinearLayout> 
3

There are 3 answers

1
TAUSEEQ On

1.First create a xml file (example: border_shadow.xml) in "drawable" folder and copy the below code into it.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <item>
        <shape>
            <!-- set the shadow color here -->
            <stroke
                android:width="2dp"
                android:color="#7000" />
            <!-- setting the thickness of shadow (positive value will give shadow on that side) -->
            <padding
                android:bottom="2dp"
                android:left="2dp"
                android:right="-1dp"
                android:top="-1dp" />

            <corners android:radius="3dp" />
        </shape>
    </item>
    <item>
        <shape>
            <solid android:color="#fff" />
            <corners android:radius="3dp" />
        </shape>
    </item>
</layer-list>

Now set as Background of Linear Layout:

0
Faraz Ahmed On

There is an option to remove paddings in the image created by the tool you mentioned

1
Anorov Hasan On

I just override " Widget.AppCompat.Button.Borderless " this theme and it removes 9-patch shadow

enter image description here