本文整理匯總了C#中Android.SetPadding方法的典型用法代碼示例。如果您正苦於以下問題:C# Android.SetPadding方法的具體用法?C# Android.SetPadding怎麽用?C# Android.SetPadding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Android
的用法示例。
在下文中一共展示了Android.SetPadding方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: UpdateBackground
public static void UpdateBackground(Border border, Android.Views.View view)
{
var strokeThickness = border.StrokeThickness;
var context = view.Context;
// create stroke drawable
GradientDrawable strokeDrawable = null;
// if thickness exists, set stroke drawable stroke and radius
if(strokeThickness.HorizontalThickness + strokeThickness.VerticalThickness > 0) {
strokeDrawable = new GradientDrawable ();
strokeDrawable.SetColor (border.BackgroundColor.ToAndroid ());
// choose thickest margin
// the content is padded so it will look like the margin is with the given thickness
strokeDrawable.SetStroke ((int)context.ToPixels (strokeThickness.ThickestSide()), border.Stroke.ToAndroid ());
strokeDrawable.SetCornerRadius ((float)border.CornerRadius);
}
// create background drawable
var backgroundDrawable = new GradientDrawable ();
// set background drawable color based on Border's background color
backgroundDrawable.SetColor (border.BackgroundColor.ToAndroid ());
backgroundDrawable.SetCornerRadius((float)border.CornerRadius);
if (strokeDrawable != null) {
// if stroke drawable exists, create a layer drawable containing both stroke and background drawables
var ld = new LayerDrawable (new Drawable[] { strokeDrawable, backgroundDrawable });
ld.SetLayerInset (1, (int)context.ToPixels (strokeThickness.Left), (int)context.ToPixels (strokeThickness.Top), (int)context.ToPixels (strokeThickness.Right), (int)context.ToPixels (strokeThickness.Bottom));
view.SetBackgroundDrawable (ld);
} else {
view.SetBackgroundDrawable (backgroundDrawable);
}
// set Android.View's padding to take into account the stroke thickiness
view.SetPadding (
(int)context.ToPixels (strokeThickness.Left + border.Padding.Left),
(int)context.ToPixels (strokeThickness.Top + border.Padding.Top),
(int)context.ToPixels (strokeThickness.Right + border.Padding.Right),
(int)context.ToPixels (strokeThickness.Bottom + border.Padding.Bottom));
}