[FREE/OS] SimpleCardView - a simple card view for HVArrangements

🧩 SimpleCardView

An extension for MIT App Inventor 2.
Developed by TIMAI2 using Fast.

:memo: Specifications


:package: Package: uk.co.metricrat.simplecardview
:floppy_disk: Size: 5.29 KB
:gear: Version: 1.0
:mobile_phone: Minimum API Level: 14
:date: Updated On: 2026-08-28T23:00:00Z
:laptop: Built & documented using: FAST v7.0.0-premium

Method:

SimpleCardView has total 1 method.

1. Create

creates cardview from HVArrangement, and provides for a selection of display properties

Parameter Type
arrangement component
bgColour number
cornerRadius number
borderWidth number
borderColour number
margin number
padding number
elevation number

2. Block

3. Example Usage

4. Extension

SimpleCardView

5. Source Code

simplecardview.java
package uk.co.metricrat.simplecardview;

import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.view.ViewGroup;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.HVArrangement;

@DesignerComponent(
	version = 1,
	versionName = "1.0",
	description = "Developed by TIMAI2 using Fast.",
	iconName = "icon.png"
)
public class SimpleCardView extends AndroidNonvisibleComponent {

	public SimpleCardView(ComponentContainer container) {
		super(container.$form());
	}

    @SimpleFunction("creates cardview from HVA")
	public void Create(HVArrangement arrangement, int bgColour, int cornerRadius, int borderWidth, int borderColour, int margin, int padding, int elevation)  {
		View cardview = arrangement.getView();
		GradientDrawable gradDraw = new GradientDrawable();
		//sets background colour
		gradDraw.setColor(bgColour);
		//sets rounded corners
		gradDraw.setCornerRadius(setPixels(cornerRadius));
		//sets borderWidth and colour
		gradDraw.setStroke(setPixels(borderWidth), borderColour);
		//sets elevation
		cardview.setElevation(setPixels(elevation));
		//sets padding
		cardview.setPadding(setPixels(padding), setPixels(padding), setPixels(padding), setPixels(padding));
		//sets margin
		ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) cardview.getLayoutParams();
		params.setMargins(setPixels(margin), setPixels(margin), setPixels(margin), setPixels(margin));
		cardview.setLayoutParams(params);
		cardview.requestLayout();
		cardview.setBackground(gradDraw);
	}

	// function to convert dp to pixels
	public int setPixels(int element) {
		return Math.round((float)element * this.form.deviceDensity());
	}

}

Enjoy :smiley: , and all feedback and comments welcome.

Available for use in any MIT AppInventor projects or competitions

#####################################################################
This work by TIMAI2 is licensed under a
Creative Commons Attribution-ShareAlike 4.0 Unported License with attribution.
Please use name = TIMAI2 and link to this source page when giving credit.
#####################################################################

4 Likes

Isn't the same possible with @Kevinkun's Enhance extension? :face_with_monocle: :thinking:

Yep, but this is a cut down simple version to just create a card view of an HVA.