【问题标题】:xamarin android rounded imageview height and width adjustmentxamarin android圆形imageview高度和宽度调整
【发布时间】:2017-07-25 14:26:57
【问题描述】:

我正在使用 xamarin android native 进行应用程序开发。我使用以下代码对 ImageView 上位图的图像进行四舍五入。

<ImageView
      android:id="@+id/proimg"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/pro1" />

在代码中,

imgpro.SetImageBitmap(bitmap);
imgpro.SetImageDrawable(ImageHelper.getRoundedCornerImage(bitmap, 120));

public class ImageHelper
{

            public static Android.Support.V4.Graphics.Drawable.RoundedBitmapDrawable getRoundedCornerImage(Bitmap thePic, int cornerRadius)
            {
                Android.Support.V4.Graphics.Drawable.RoundedBitmapDrawable dr = Android.Support.V4.Graphics.Drawable.RoundedBitmapDrawableFactory.Create(null, thePic);
                dr.CornerRadius = cornerRadius;
                return dr;
            }
}

但图像带有如下空白区域(空白区域以红色标记突出显示):

图像不会根据 ImageView 进行调整。

谁能帮我解决这个问题。

提前致谢

【问题讨论】:

    标签: xamarin.android


    【解决方案1】:

    试试这个:

    <ImageView
           android:id="@+id/proimg"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:scaleType="centerCrop"
           android:adjustViewBounds="true
           android:src="@drawable/pro1" />
    

    【讨论】:

    • 您好泰尔,感谢您的及时回复。但它不起作用。能否请教我其他解决方案?
    • 我建议您使用布局而不是位图来舍入图像。该问题的第一个答案解释了如何做到这一点stackoverflow.com/questions/22105775/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-15
    • 2014-08-25
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    相关资源
    最近更新 更多