private void setTabBG(int tab1, int tab2) { if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBeanMr1) { ViewGroup tabStrip = (ViewGroup)tabLayout.GetChildAt(0); View tabView1 = tabStrip.GetChildAt(0); View tabView2 = tabStrip.GetChildAt(1); if (tabView1 != null) { int paddingStart = tabView1.PaddingStart; int paddingTop = tabView1.PaddingTop; int paddingEnd = tabView1.PaddingEnd; int paddingBottom = tabView1.PaddingBottom; ViewCompat.SetBackground(tabView1, AppCompatResources.GetDrawable(this.Context, tab1)); ViewCompat.SetPaddingRelative(tabView1, paddingStart, paddingTop, paddingEnd, paddingBottom); } if (tabView2 != null) { int paddingStart = tabView2.PaddingStart; int paddingTop = tabView2.PaddingTop; int paddingEnd = tabView2.PaddingEnd; int paddingBottom = tabView2.PaddingBottom; ViewCompat.SetBackground(tabView2, AppCompatResources.GetDrawable(this.Context, tab2)); ViewCompat.SetPaddingRelative(tabView2, paddingStart, paddingTop, paddingEnd, paddingBottom); } } }
private void AdjustDetailsLayout() { if (IsLargeTablet(AppCompatActivity)) { AppCompatActivity?.RunOnUiThread(() => { if (this.View == null) { return; } var panel = (Android.Support.V7.Widget.GridLayout)detailsPanel; // Minimum width for ea. card int minWidth = 600; // Size of the view int viewWidth = (int)(this.View.Width - panel.PaddingEnd - panel.PaddingStart); // Available columns based on min card width int availColumns = (viewWidth / minWidth) == 0 ? 1 : viewWidth / minWidth; // Maximum columns to use int maxColumns = (availColumns > panel.ChildCount) ? panel.ChildCount : availColumns; int freeSpace = viewWidth - (minWidth * maxColumns); // Increase card width to fill available space int itemWidth = minWidth + (freeSpace / maxColumns); // Adjust GridLayout // Start int currCol = 0; int currRow = 0; for (int i = 0; i < panel.ChildCount; i++) { View view = panel.GetChildAt(i); var layoutParams = new Android.Support.V7.Widget.GridLayout.LayoutParams( Android.Support.V7.Widget.GridLayout.InvokeSpec(currRow, 1.0f), Android.Support.V7.Widget.GridLayout.InvokeSpec(currCol, 1.0f)) { Width = 0 }; int paddingVert = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 10, view.Context.Resources.DisplayMetrics); ViewCompat.SetPaddingRelative(view, paddingVert, 0, paddingVert, 0); // s, t, e, b view.LayoutParameters = layoutParams; if (currCol == maxColumns - 1) { currCol = 0; currRow++; } else { currCol++; } } panel.RowCount = GridLayout.Undefined; panel.ColumnCount = maxColumns; }); } }