Showing Shadow LinearLayout (SSL)


SSL:   SOLD       




Hi Dev, I first learned to create Android application UIs using XML, and so far I have tried with not very significant results, as an illustration, here is how my efforts have been so far.

<LinearLayout
 android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@xml/rounded_rect_shape"
android:orientation="vertical"
android:padding="10dp">
<-- My buttons, textviews, Imageviews go here -->
</LinearLayout>

I've also created a shape drawable to manipulate the LinearLayout component to make it appear to have a shadow, here's my attempt so far.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
   android:shape="rectangle" >

   <solid android:color="#ffffff" />

   <corners
      android:bottomLeftRadius="3dp"
      android:bottomRightRadius="3dp"
      android:topLeftRadius="3dp"
      android:topRightRadius="3dp" />
</shape>

It was mentioned in the forum that apparently there are several ways to achieve such results, including:

  • Add a grey LinearLayout color (think of this as an outer wrapper layer), then inside it there is another LinearLayout as an inner wrapper layer, now on this inner wrapper layer please make margin-bottom and margin-end with the same value, maybe around 2 or 3dp, please adjust it to your taste.
  • Another way is to use a shape in the drawable package, as I did previously (as above), only this time I slightly corrected the results of my work when I was still a newbie, it should be more or less like this.

Let's say the file name is background_with_shadow.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item >
        <shape 
            android:shape="rectangle">
        <solid android:color="@android:color/darker_gray" />
        <corners android:radius="5dp"/>
        </shape>
    </item>
    <item android:right="1dp" android:left="1dp" android:bottom="2dp">
        <shape 
            android:shape="rectangle">
        <solid android:color="@android:color/white"/>
        <corners android:radius="5dp"/>
        </shape>
    </item>
</layer-list>

Then implement it on the layout you mean, something like this.

<LinearLayout
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@drawable/background_with_shadow"/>

Post a Comment

Previous Next

نموذج الاتصال