本文整理汇总了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));
}