当前位置: 首页>>代码示例>>C#>>正文


C# Android.SetCompoundDrawables方法代码示例

本文整理汇总了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);
                }
            }
        }
开发者ID:Jaskomal,项目名称:Xamarin-Forms-Labs,代码行数:48,代码来源:ImageButtonRenderer.cs

示例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);
                    }
                }
            }
        }
开发者ID:robertohuertasm,项目名称:Xamarin-Forms-Labs,代码行数:65,代码来源:ImageButtonRenderer.cs

示例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);
            }
        }
开发者ID:AjourMedia,项目名称:ChicagoVball,代码行数:41,代码来源:ImageButtonRenderer.cs

示例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);
                    }
                }
            }
        }
开发者ID:apcurium,项目名称:Xamarin-Forms-Labs,代码行数:55,代码来源:ImageButtonRenderer.cs


注:本文中的Android.SetCompoundDrawables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。