Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I overlay a drop shadow onto a ScrollView?

I'm looking for a way to overlay a drop shadow onto a ScrollView like this:

drop shadow example

My intention is to have another layout above and outside the ScrollView (the green one) that stays at the top while scrolling the content of the ScrollView. The ScrollView should have a drop shadow overlay at the top which appears to be from the layout above.

Since I want the content of the ScrollView to scroll into the drop shadow, that shadow must not be part of the layout above, otherwise the drop shadow would stay seperated from the scrolling contents below.

Any ideas how I can bring that drop shadow to life? I found android:foreground but then read that it wouldn't work on ScrollViews.

like image 230
machtnix Avatar asked Jul 15 '12 22:07

machtnix


1 Answers

Ok, found a solution to do this. This is what I did:

To have a drop shadow image overlay on the ScrollView, I put the ScrollView inside a FrameLayout and applied the drop shadow drawable to the FrameLayout via android:foreground.

    <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:foreground="@drawable/drop_shadow_bitmap"
    android:foregroundGravity="top|fill_horizontal" >

    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top" >
like image 163
machtnix Avatar answered Sep 23 '22 20:09

machtnix