B4A Library MSCardView

poBu7IQl.png


This library ports the CardView present in the android v7 compatibility libraries.
CardView is used to show information organized as cards. You can use these cards in a scrollview or a listview (ULV) or gridview etc.
The CardView is just a view that contains a panel.

Setup:
You do not need to reference and library to work with this, however you need to reference the resource files.
Add the following in your project attributes:
B4X:
#AdditionalRes: H:\Eclipse\adt-bundle-windows-x86_64\sdk\extras\android\support\v7\cardview\res
*Replace the path with your AndroidSDK path. Also note you need to update your SDK and support libraries.

Copy MSCardView.xml and MSCardView.jar from this post into your Addtional Libraries folder.

CardView Specific Properties and Methods:
MaxElevation, Elevation, Radius, setPadding
These are all self explanatory.

Using CardView:

Example usage:
B4X:
'Create a Holder panel
Dim spanel AsPanel

spanel.Initialize("")
Activity.AddView(spanel, 0dip, 0dip, 100%x, 100%y)

'Create the CardViews
   Dim cv As MSCardView
    cv.Initialize("CV")
    cv.MaxElevation = 10dip
    cv.Elevation = 4dip
    spanel.AddView(cv, 10dip, 255dip, 100%x - 20dip, 96dip)

    Dim cv2,cv3 As MSCardView
    cv2.Initialize("")
    cv3.Initialize("")
    spanel.AddView(cv2, 10dip, 370dip, 50%x - 20dip, 60dip)
    spanel.AddView(cv3, 50%x , 370dip, 50%x - 20dip, 60dip)

    cv2.Radius = 50
    cv3.MaxElevation = 1dip
    cv3.Elevation = 2dip
    Dim etnew As EditText
    etnew.Initialize("")
    cv3.setPadding(50dip,5dip,10dip,5dip)
    cv3.Panel.AddView(etnew,0,0,-1,-1)

MSCardView
Author:
thedesolatesoul
Version: 0.01
  • MSCardView
    Methods:
    • BringToFront
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • setPadding (l As Int, t As Int, r As Int, b As Int)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Elevation As Float
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • MaxElevation As Float
    • Panel As PanelWrapper [read only]
    • Radius As Float
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
 

Attachments

  • MSCardView.zip
    25.7 KB · Views: 1,482
Last edited:

xor83

Member
Licensed User
Longtime User
Cannot find the res folder. I have this path: C:\android\extras\android\m2repository\com\android\support\cardview-v7\23.0.0

Got this error message:
invalid resource directory name: c:\android\extras\android\m2repository\com\android\support\cardview-v7 21.0.0
invalid resource directory name: c:\android\extras\android\m2repository\com\android\support\cardview-v7 21.0.2
invalid resource directory name: c:\android\extras\android\m2repository\com\android\support\cardview-v7 21.0.3
 

DonManfred

Expert
Licensed User
Longtime User
Cannot find the res folder. I have this path: C:\android\extras\android\m2repository\com\android\support\cardview-v7\23.0.0
You need to remove the resourcefolder-reference. Remove the #additionalres line and add
B4X:
#additionaljar: com.android.support:cardview-v7
instead

Hopefully it works...
 

xor83

Member
Licensed User
Longtime User
I am also getting this error:

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v7/widget/CardViewJellybeanMr1;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)


I am using MSCardView

Please help.
 

thedesolatesoul

Expert
Licensed User
Longtime User
The library jar file includes classes from the support library. This is a mistake. You will need to open the jar file with 7zip and remove the android folder.
I dont think the mistake was to include the classes. The mistake was not to rename them to something else. I didnt want to re-code the wrapper everytime google changed the support library.
 

Kwame Twum

Active Member
Licensed User
Longtime User
Kindly disabled the logs in your library... it's irritating if you have a list of CardViews to scroll through. Your logcat ends up having lots of those. This wastes time since a user might not readily find their own logs.
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
Wow, this is cool stuff, just experimented with this library and used layouts to load to the cards. Thing is even if you set your anchors, these dont get adjusted when the layout is loaded to the card. As I was checking out views that fit the whole width of the card, I had to adjust the width after loading the layout to the card.

B4X:
Sub SetUpCards
    cv1.MaxElevation = 10dip
    cv1.Elevation = 4dip
    cv1.Radius = 0dip
    cv1.Panel.LoadLayout("card1")
    txtFirstName.Width = cv1.Width - 40dip

    cv2.Panel.LoadLayout("card2")
    cv2.Radius = 5
    cv2.MaxElevation = 10dip
    cv2.Elevation = 5dip

    btnCard2.Width = cv2.Width - 40dip
    cboSpinner.Width = cv2.Width - 40dip
End Sub

NB: All I had to do was to reference the MSCardView library only. Adding the AdditionalRes created an exception. You can check the example herein and see the designer layouts. Overall, this is brilliant stuff!!!

card1.png card2.png
 

Attachments

  • MSCardView.zip
    17.4 KB · Views: 311
Top