I created a custom component that extends ContentView and a visualizer that displays CardView on Android.
The problem I am facing is that the contents of the forms are displayed below CardView. On KitKat, this does not happen, but I think the implementation of CardView is not the same as Lollipop or newer.
Setting the background color in CardView to transparent (0x00000000) shows the contents below CardView.
Component Forms:
using Xamarin.Forms; namespace CodeFest { public class NativeClientProfile : ContentView { public NativeClientProfile() { var grid = new Grid { RowDefinitions = new RowDefinitionCollection {new RowDefinition()}, ColumnDefinitions = new ColumnDefinitionCollection {new ColumnDefinition(), new ColumnDefinition()} }; grid.Children.Add(new Label {Text = "FSP No"}, 0, 0); grid.Children.Add(new Label {Text = "12345", HorizontalTextAlignment = TextAlignment.Center}, 1, 0); grid.Children.Add(new Label {Text = "Risk"}, 0, 1); grid.Children.Add( new Label {Text = "Low", TextColor = Color.Green, HorizontalTextAlignment = TextAlignment.Center}, 1, 1); var item = new Label { Text = "Foo bar", HorizontalTextAlignment = TextAlignment.Center, FontSize = 30, FontAttributes = FontAttributes.Bold }; Content = new StackLayout { Children = { item, new Label { Text = "Financial Services Provider", HorizontalTextAlignment = TextAlignment.Center }, grid } }; } } }
User renderer:
using Android.Support.V7.Widget; using Android.Text; using Android.Views; using CodeFest; using CodeFest.Droid.ComponentRenderers; using Xamarin.Forms; using Xamarin.Forms.Platform.Android; [assembly: ExportRenderer(typeof(NativeClientProfile), typeof(NativeClientProfileRenderer))] namespace CodeFest.Droid.ComponentRenderers { class NativeClientProfileRenderer : ViewRenderer<NativeClientProfile, CardView> { protected override void OnElementChanged(ElementChangedEventArgs<NativeClientProfile> elementChangedEventArgs) { var view = new CardView(Context);
I am looking for an example of how to properly visualize form components in a CardView custom renderer.
xamarin xamarin.android xamarin.forms
Justin
source share