I am trying to create some views programmatically to match a mock-up that I have made in an XML layout, but they are displaying differently despite seemingly having the same properties.
The card on the left is created using the XML below, the one on the right is created using code. The correct layout is the one on the left, where is my code wrong?
XML (left image)
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:id="@+id/cardViewContainer"
android:layout_height="200dp">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/testCard">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="200dp"
android:minWidth="200dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TEST TITLE"
android:layout_weight="1"
android:layout_gravity="bottom"
android:gravity="center"
android:layout_margin="5px" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Code (right image)
var layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent);
int cardMinDims = (int)(200 * scale + 0.5f);
TextView title = new TextView(this);
title.Text = "TEST TITLE";
title.Gravity = GravityFlags.Center;
var title_layoutParams = layoutParams;
title_layoutParams.Weight = 1;
title_layoutParams.Gravity = GravityFlags.Bottom;
title_layoutParams.SetMargins(5, 5, 5, 5);
LinearLayout layout = new LinearLayout(this);
layout.SetMinimumHeight(cardMinDims);
layout.SetMinimumWidth(cardMinDims);
layout.Orientation = Orientation.Vertical;
layout.AddView(title,title_layoutParams);
CardView card = new CardView(this);
card.AddView(layout, layoutParams);
LinearLayout cardViewContainer = FindViewById<LinearLayout>(Resource.Id.cardViewContainer);
cardViewContainer.AddView(card,layoutParams);