本文整理汇总了C#中Android.SetCompoundDrawables方法的典型用法代码示例。如果您正苦于以下问题:C# Android.SetCompoundDrawables方法的具体用法?C# Android.SetCompoundDrawables怎么用?C# Android.SetCompoundDrawables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android
的用法示例。
在下文中一共展示了Android.SetCompoundDrawables方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetImageSourceAsync
/// <summary>
/// Sets the image source.
/// </summary>
/// <param name="targetButton">The target button.</param>
/// <param name="model">The model.</param>
/// <param name="imageSource">Optional source for disabled image.</param>
/// <returns>A <see cref="Task"/> for the awaited operation.</returns>
private async Task SetImageSourceAsync(Android.Widget.Button targetButton, ImageButton model)
{
const int Padding = 10;
var source = model.IsEnabled ? model.Source : model.DisabledSource ?? model.Source;
using (var bitmap = await this.GetBitmapAsync(source))
{
if (bitmap != null)
{
Drawable drawable = new BitmapDrawable(bitmap);
var scaledDrawable = GetScaleDrawable(drawable, GetWidth(model.ImageWidthRequest),
GetHeight(model.ImageHeightRequest));
Drawable left = null;
Drawable right = null;
Drawable top = null;
Drawable bottom = null;
targetButton.CompoundDrawablePadding = Padding;
switch (model.Orientation)
{
case ImageOrientation.ImageToLeft:
targetButton.Gravity = GravityFlags.Left | GravityFlags.CenterVertical;
left = scaledDrawable;
break;
case ImageOrientation.ImageToRight:
targetButton.Gravity = GravityFlags.Right | GravityFlags.CenterVertical;
right = scaledDrawable;
break;
case ImageOrientation.ImageOnTop:
top = scaledDrawable;
break;
case ImageOrientation.ImageOnBottom:
bottom = scaledDrawable;
break;
}
targetButton.SetCompoundDrawables(left, top, right, bottom);
}
}
}
示例2: SetImageSourceAsync
/// <summary>
/// Sets the image source.
/// </summary>
/// <param name="targetButton">The target button.</param>
/// <param name="model">The model.</param>
/// <returns>A <see cref="Task"/> for the awaited operation.</returns>
private async Task SetImageSourceAsync(Android.Widget.Button targetButton, ImageButton model)
{
if (targetButton == null || targetButton.Handle == IntPtr.Zero || model == null) return;
// const int Padding = 10;
var source = model.IsEnabled ? model.Source : model.DisabledSource ?? model.Source;
using (var bitmap = await GetBitmapAsync(source).ConfigureAwait(false))
{
if (bitmap == null)
targetButton.SetCompoundDrawables(null, null, null, null);
else
{
var drawable = new BitmapDrawable(bitmap);
var tintColor = model.IsEnabled ? model.ImageTintColor : model.DisabledImageTintColor;
if (tintColor != Color.Transparent)
{
drawable.SetTint(tintColor.ToAndroid());
drawable.SetTintMode(PorterDuff.Mode.SrcIn);
}
using (var scaledDrawable = GetScaleDrawable(drawable, GetWidth(model.ImageWidthRequest), GetHeight(model.ImageHeightRequest)))
{
Drawable left = null;
Drawable right = null;
Drawable top = null;
Drawable bottom = null;
//System.Diagnostics.Debug.WriteLine($"SetImageSourceAsync intptr{targetButton.Handle}");
int padding = 10; // model.Padding
targetButton.CompoundDrawablePadding = RequestToPixels(padding);
switch (model.Orientation)
{
case ImageOrientation.ImageToLeft:
targetButton.Gravity = GravityFlags.Left | GravityFlags.CenterVertical;
left = scaledDrawable;
break;
case ImageOrientation.ImageToRight:
targetButton.Gravity = GravityFlags.Right | GravityFlags.CenterVertical;
right = scaledDrawable;
break;
case ImageOrientation.ImageOnTop:
targetButton.Gravity = GravityFlags.Top | GravityFlags.CenterHorizontal;
top = scaledDrawable;
break;
case ImageOrientation.ImageOnBottom:
targetButton.Gravity = GravityFlags.Bottom | GravityFlags.CenterHorizontal;
bottom = scaledDrawable;
break;
case ImageOrientation.ImageCentered:
targetButton.Gravity = GravityFlags.Center; // | GravityFlags.Fill;
top = scaledDrawable;
break;
}
targetButton.SetCompoundDrawables(left, top, right, bottom);
}
}
}
}
示例3: SetImageSource
/// <summary>
/// Sets the image source.
/// </summary>
/// <param name="targetButton">The target button.</param>
/// <param name="model">The model.</param>
private void SetImageSource(Android.Widget.Button targetButton, Core.Helpers.Controls.ImageButton model)
{
var packageName = Context.PackageName;
const int padding = 0;
const string resourceType = "drawable";
var resId = Resources.GetIdentifier (model.Image, resourceType, packageName);
if (resId > 0) {
var scaledDrawable = GetScaleDrawableFromResourceId (resId, GetWidth (model.ImageWidthRequest),
GetHeight (model.ImageHeightRequest));
Drawable left = null;
Drawable right = null;
Drawable top = null;
Drawable bottom = null;
targetButton.CompoundDrawablePadding = padding;
switch (model.Orientation) {
case (ImageOrientation.ImageToLeft):
targetButton.Gravity = GravityFlags.Left | GravityFlags.CenterVertical;
left = scaledDrawable;
break;
case (ImageOrientation.ImageToRight):
targetButton.Gravity = GravityFlags.Right | GravityFlags.CenterVertical;
right = scaledDrawable;
break;
case (ImageOrientation.ImageOnTop):
top = scaledDrawable;
break;
case (ImageOrientation.ImageOnBottom):
bottom = scaledDrawable;
break;
}
targetButton.SetCompoundDrawables (left, top, right, bottom);
}
}
示例4: SetImageSourceAsync
/// <summary>
/// Sets the image source.
/// </summary>
/// <param name="targetButton">The target button.</param>
/// <param name="model">The model.</param>
/// <returns>A <see cref="Task"/> for the awaited operation.</returns>
private async Task SetImageSourceAsync(Android.Widget.Button targetButton, ImageButton model)
{
if (targetButton == null || model == null)
return;
const int Padding = 10;
var source = model.IsEnabled ? model.Source : model.DisabledSource ?? model.Source;
using (var bitmap = await this.GetBitmapAsync(source))
{
if (bitmap != null)
{
var drawable = new BitmapDrawable(bitmap);
var tintColor = model.IsEnabled ? model.ImageTintColor : model.DisabledImageTintColor;
if (tintColor != Xamarin.Forms.Color.Transparent)
{
drawable.SetTint(tintColor.ToAndroid());
drawable.SetTintMode(PorterDuff.Mode.SrcIn);
}
using (var scaledDrawable = GetScaleDrawable (drawable, GetWidth (model.ImageWidthRequest),
GetHeight (model.ImageHeightRequest))) {
Drawable left = null;
Drawable right = null;
Drawable top = null;
Drawable bottom = null;
targetButton.CompoundDrawablePadding = Padding;
switch (model.Orientation) {
case ImageOrientation.ImageToLeft:
targetButton.Gravity = GravityFlags.Left | GravityFlags.CenterVertical;
left = scaledDrawable;
break;
case ImageOrientation.ImageToRight:
targetButton.Gravity = GravityFlags.Right | GravityFlags.CenterVertical;
right = scaledDrawable;
break;
case ImageOrientation.ImageOnTop:
top = scaledDrawable;
break;
case ImageOrientation.ImageOnBottom:
bottom = scaledDrawable;
break;
}
targetButton.SetCompoundDrawables (left, top, right, bottom);
}
}
}
}