Since there were some problems in the past with MSCardView library I created my own version.
Features:
Installation:
Copy all files of the library zip file (.xml, .jar, .aar) to your additional libraries folder.
You need to have the Android Support repository installed with SDK Manager.
This library will work with B4A 6.30 and above.
Some usage notes:
CardView behaves differently on Android versions >= 21 (Lollipop) and <21.
On API 21 and above everything is nice.
Clipping of the rounded edges is done automatically and the shadow of the card is drawn by the system.
If you want to support Api versions below 21 you have to consider the following things:
The shadow is drawn by the CardView itself on API<21 so it has to add some margin around the view. Therefore the card is smaller on these devices than on devices with API21 and up. If you want to add the same margin/padding for the shadow for API21+ devices then you can set CardView.UseCompatPadding=true.
The size of the margin/padding which is needed for the shadow depends on the maximum elevation of the card. You can set the maximum elevation with CardView.MaxElevation=4dip. Keep the max. elevation small because the bigger this value is the smaller your card will get.
The second difference is that by default a card on devices with API21+ has no inner padding but cards on devices with API<21 add a padding to the card contents to prevent that the contents are drawn above the rounded corners. So the content area on API<21 devices is smaller. You can disable this with CardView.PreventCornerOverlap=false (default is true). If you want the content to be the same size you can manually add padding with CardView.SetContentPadding(Left, Top, Right, Bottom) and set CardView.PreventCornerOverlap=false.
Positioning Views on a CardView can be a bit tricky because the inner content size is not exactly known on API<21 devices.
I strongly suggest to use CardView.LoadLayout() to add content to a card. In the Layout 100%x is the width of the card and 100%y is the height of the card. So with designer scripting and anchors you can exactly position your content. In short words: CardView.LoadLayout() takes care of the content area size of the card on all API versions.
Reference Documentation:
CardView
Author: Markus Stipp
Version: 1
V1.0:
Features:
- Add cards to your activity with B4A Designer or by code.
- Most properties settable in designer
- Load a layout to the cards with LoadLayout()
Installation:
Copy all files of the library zip file (.xml, .jar, .aar) to your additional libraries folder.
You need to have the Android Support repository installed with SDK Manager.
This library will work with B4A 6.30 and above.
Some usage notes:
CardView behaves differently on Android versions >= 21 (Lollipop) and <21.
On API 21 and above everything is nice.
Clipping of the rounded edges is done automatically and the shadow of the card is drawn by the system.
If you want to support Api versions below 21 you have to consider the following things:
The shadow is drawn by the CardView itself on API<21 so it has to add some margin around the view. Therefore the card is smaller on these devices than on devices with API21 and up. If you want to add the same margin/padding for the shadow for API21+ devices then you can set CardView.UseCompatPadding=true.
The size of the margin/padding which is needed for the shadow depends on the maximum elevation of the card. You can set the maximum elevation with CardView.MaxElevation=4dip. Keep the max. elevation small because the bigger this value is the smaller your card will get.
The second difference is that by default a card on devices with API21+ has no inner padding but cards on devices with API<21 add a padding to the card contents to prevent that the contents are drawn above the rounded corners. So the content area on API<21 devices is smaller. You can disable this with CardView.PreventCornerOverlap=false (default is true). If you want the content to be the same size you can manually add padding with CardView.SetContentPadding(Left, Top, Right, Bottom) and set CardView.PreventCornerOverlap=false.
Positioning Views on a CardView can be a bit tricky because the inner content size is not exactly known on API<21 devices.
I strongly suggest to use CardView.LoadLayout() to add content to a card. In the Layout 100%x is the width of the card and 100%y is the height of the card. So with designer scripting and anchors you can exactly position your content. In short words: CardView.LoadLayout() takes care of the content area size of the card on all API versions.
Your support:
Creating libraries and wrappers for existing library projects is a lot of work. The use of this library is totally free and you even don't need to mention in your app that you use it.
But if you use this library in your projects and you think it is useful to you please consider to make a donation:
Thanks very much for your support.
Reference Documentation:
CardView
Author: Markus Stipp
Version: 1
- CardView
Events:- Click
- LongClick
- AddView (View As View, Left As Int, Top As Int, Width As Int, Height As Int)
Add a View to the CardView object - BringToFront
- DesignerCreateView (base As PanelWrapper, label As LabelWrapper, props As Map)
This method is only for the B4A Designer. Don't call it directly - Initialize (EventName As String)
Initializes the object - Invalidate
- Invalidate2 (Rect As Rect)
Invalidate a rectangualar part of the object - Invalidate3 (Left As Int, Top As Int, Right As Int, Bottom As Int)
Invalidate part of the object - IsInitialized As Boolean
- LoadLayout (LayoutFile As String)
- RemoveAllViews
Remove all views from the card. - RemoveView
- RequestFocus As Boolean
- SendToBack
- SetBackgroundImage (arg0 As Bitmap)
- SetColorAnimated (Duration As Int, FromColor As Int, ToColor As Int)
Animate the color to a new value - SetContentPadding (Left As Int, Top As Int, Right As Int, Bottom As Int)
Sets the padding for the content. - SetLayout (Left As Int, Top As Int, Width As Int, Height As Int)
Changes the View position and size. - SetLayoutAnimated (Duration As Int, Left As Int, Top As Int, Width As Int, Height As Int)
Similar to SetLayout. Animates the change. Note that the animation will only be applied when running on Android 3+ devices.
Duration - duration of the layout change - SetVisibleAnimated (Duration As Int, Visible As Boolean)
Fade the view in or out
- Color As Int [write only]
Sets the Background Color of the Card. - CornerRadius As Float
Sets or gets the corner radius. - Elevation As Float
Sets or gets the Card elevation. - Enabled As Boolean
- Height As Int
Gets or sets the view's height - Left As Int
Gets or sets the view's left position - MaxElevation As Float
Sets the maximum elevation - Parent As Object [read only]
- PreventCornerOverlap As Boolean
Set this attribute to true to add padding when your app is running on earlier Android versions (API level 20 and earlier). This setting prevents CardView content from intersecting with the CardView's rounded corners. - Tag As Object
- Top As Int
Gets or sets the view's top position - UseCompatPadding As Boolean
Set this attribute to true to add padding when your app is running in versions of Android at or greater than API level 21. If you want to use CardView on pre-Lollipop devices and have it look the same on Lollipop (or later), set this attribute to true. When this attribute is enabled, CardView adds additional padding to draw shadows when it runs on pre-Lollipop devices. This helps to overcome the differences in padding that are introduced when pre-Lollipop programmatic shadow implementations are in effect. - Visible As Boolean
- Width As Int
Gets or sets the view's width
V1.0:
- Initial version
- Removed ba field
- Some minor bug fixes
Attachments
Last edited: