B4A Class Shadow

Recently I've read few questions about adding shadow to views and decided to make a class for it.
It "just" adds a panel with the required color under the defined view.
Simple methods:
- Initialize(Parent As Panel, V As View, color As Int, angle As Float, margin As Float, radius As Float)
- SetColor(color As Int, radius As Float)
- SetMargin(margin As Float)
- SetAngle(angle As Float)

There is a demo attached.
Comments are welcome !

Edit: Version 2 is here with two more features:
1. When using a bitmap with transparent parts, set -1 as radius (in initialization and in SetColor).
2. Shadow can be rotated but you should rotate it in the same angle you rotate the view...
- SetRotation( Angle As Float)

Edit: Ver. 2.1 - SetRotation rotates the view and the shadow in the defined angle, in degrees

Edit: Ver 2.2 - per Cableguy's request I added option for a gradient shadow. I had to rebuild most of the class, it has an initialization which is just for init, then you have to call start1 or start2. start1 is one color, start2 is gradient. I leave both on for download, if you don't need the gradient - use 2.1
 

Attachments

  • shadow2.png
    shadow2.png
    53.1 KB · Views: 1,180
  • shadow2.1.zip
    139.8 KB · Views: 536
  • shadow_2.2.zip
    140 KB · Views: 659
Last edited:

derez

Expert
Licensed User
Longtime User
Attached a demo of a clock with shadows.
Edit: updated the demo with a button to show real time and display a digital time for those who never learned how to read an analog clock...
 

Attachments

  • clockdemo.png
    clockdemo.png
    83.8 KB · Views: 678
  • clockdemo.zip
    78.6 KB · Views: 386
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Hi Derez,

I have a request: Add an Alpha value to the shadow; I know I can pass it with the shadow color but I would like to achieve a gradiented shadow, going from a solid shadow to a set Alpha value.
 

derez

Expert
Licensed User
Longtime User
Cableguy:
I know I can pass it with the shadow color but I would like to achieve a gradiented shadow, going from a solid shadow to a set Alpha value
I uploaded ver 2.2 which handles gradient, in the gradient colors you can define colors.ARGB so you have the alfa.
Didn't test too much so please check also.
 

zakker

Member
Licensed User
java.lang.RuntimeException: Method: setRotation not found in: anywheresoftware.b4a.BALayout

Why??? :(
 

zakker

Member
Licensed User
Note that the android.jar is not relevant to this error as this is a run time error. android.jar only affects compile time errors.

View.setRotation was added in Android 3 (API 11). It will not work on older versions of Android.

Yes Erel, it's my fault !! I was debugging on an old 2.0.3 device... I've tried on a 6.0 and it works fine.

Thank you !!!!
 
Top