Пример #1
0
        void SetImages(MvvmAspire.Controls.Entry element)
        {
            int leftResourceId = 0, topResourceId = 0, rightResourceId = 0, bottomResourceId = 0;

            if (element.ImageLeft != null && element.ImageLeft.File != null)
            {
                leftResourceId = UIHelper.GetDrawableResource(element.ImageLeft);
            }
            if (element.ImageTop != null && element.ImageTop.File != null)
            {
                topResourceId = UIHelper.GetDrawableResource(element.ImageTop);
            }
            if (element.ImageRight != null && element.ImageRight.File != null)
            {
                rightResourceId = UIHelper.GetDrawableResource(element.ImageRight);
            }
            if (element.ImageBottom != null && element.ImageBottom.File != null)
            {
                bottomResourceId = UIHelper.GetDrawableResource(element.ImageBottom);
            }

            bool hasResource = leftResourceId > 0 || rightResourceId > 0 || topResourceId > 0 || bottomResourceId > 0;

            if (hasCompoundDrawable || hasResource)
            {
                hasCompoundDrawable = true;

                //Android.Graphics.Drawables.Drawable leftDrawable = leftResourceId > 0 ? Resources.GetDrawable(leftResourceId) : null;
                //if (leftDrawable != null)
                //    leftDrawable.SetBounds(0, 0, leftDrawable.IntrinsicWidth, leftDrawable.IntrinsicHeight);
                //Android.Graphics.Drawables.Drawable topDrawable = topResourceId > 0 ? Resources.GetDrawable(topResourceId) : null;
                //if (topDrawable != null)
                //    topDrawable.SetBounds(0, 0, topDrawable.IntrinsicWidth, topDrawable.IntrinsicHeight);
                //Android.Graphics.Drawables.Drawable rightDrawable = rightResourceId > 0 ? Resources.GetDrawable(rightResourceId) : null;
                //if (rightDrawable != null)
                //    rightDrawable.SetBounds(0, 0, rightDrawable.IntrinsicWidth, rightDrawable.IntrinsicHeight);
                //Android.Graphics.Drawables.Drawable bottomDrawable = bottomResourceId > 0 ? Resources.GetDrawable(bottomResourceId) : null;
                //if (bottomDrawable != null)
                //    bottomDrawable.SetBounds(0, 0, bottomDrawable.IntrinsicWidth, bottomDrawable.IntrinsicHeight);

                //Control.SetCompoundDrawablesRelative(leftDrawable, topDrawable, rightDrawable, bottomDrawable);
                //Control.SetCompoundDrawables(leftDrawable, topDrawable, rightDrawable, bottomDrawable);


                var leftDrawable = (leftResourceId > 0) ? Resources.GetDrawable(leftResourceId) : null;
                if (leftDrawable != null)
                {
                    if (element.ImageLeftWidth > 0)
                    {
                        leftDrawable = ResizeImage(leftDrawable, BaseUIHelper.ConvertDPToPixels(element.ImageLeftWidth), BaseUIHelper.ConvertDPToPixels(element.ImageLeftWidth));
                    }
                    else
                    {
                        Resources.GetDrawable(leftResourceId);
                    }
                }

                var topDrawable    = (topResourceId > 0) ? Resources.GetDrawable(topResourceId) : null;
                var rightDrawable  = (rightResourceId > 0) ? Resources.GetDrawable(rightResourceId) : null;
                var bottomDrawable = (bottomResourceId > 0) ? Resources.GetDrawable(bottomResourceId) : null;

                //Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(leftDrawable, topResourceId, rightResourceId, bottomResourceId);
                Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(leftDrawable, topDrawable, rightDrawable, bottomDrawable);
                Control.CompoundDrawablePadding = 20;

                if (!hasResource)
                {
                    hasCompoundDrawable = false;
                }
            }

            if (element.ImageCenter != null)
            {
                Control.SetCompoundDrawablesRelativeWithIntrinsicBounds(base.Resources.GetDrawable(UIHelper.GetDrawableResource(element.ImageCenter)), null, null, null);
                Control.Gravity = GravityFlags.Center;
            }
        }