1

我正在使用 mvvmcross 框架在 Xamarin 中创建一个 android 应用程序。

我正在尝试向我们的用户显示来自服务器的图片(图片是网址)。但是这些图片拒绝缩放以填充其父级。我怎样才能实现这些图像的正确拟合?,我在 Width 标签上使用 FillParent。但是图像拒绝缩放到容器的大小。

我目前的设置

   <FFImageLoading.Cross.MvxImageLoadingView
    android:id="@+id/my_plannymap_listitem_title_picture"
    android:layout_width="fill_parent"
    android:layout_height="150dp"
    local:MvxBind="DataLocationUri ImageUrl; Click OpenDetailCommand" />

上面的代码创建(对不起体积的东西),你可以看到图像没有填充,它们保持“原始”大小

其他活动(这里有同样的问题)

    <FFImageLoading.Cross.MvxImageLoadingView
            android:layout_width="fill_parent"
            android:layout_height="150dp"
            android:scaleType="fitCenter"
            android:id="@+id/overview_image"
            android:background="#580AB0"
            local:MvxBind="DataLocationUri ImageUrl"
            TransparencyEnabled="false"
            DownSampleToFit="true" />
4

1 回答 1

0

听起来您想将高度固定为 150dp,并将宽度固定为父级的宽度。如果是这种情况,它可以做到,但它会拉伸任何一开始就不是正确纵横比的图像。

<FFImageLoading.Cross.MvxImageLoadingView
    android:id="@+id/my_plannymap_listitem_title_picture"
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:scaleType="fitXY"
    local:MvxBind="DataLocationUri ImageUrl; Click OpenDetailCommand" />

(注意我使用了match_parent,因为fill_parent弃用

如果您不希望您的图像以一种奇怪的方式拉伸并且您不能保证传入图像的纵横比与您的布局相匹配,您需要选择一个纵横比(宽度或高度)来决定另一种是比例保持不变。您可以通过以下方式做到这一点(在这种情况下,您正在确定宽度,并根据图像的纵横比计算高度):

<FFImageLoading.Cross.MvxImageLoadingView
    android:id="@+id/my_plannymap_listitem_title_picture"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    local:MvxBind="DataLocationUri ImageUrl; Click OpenDetailCommand" />

在几乎所有无法保证缩放图像的纵横比的情况下,第二个选项比第一个选项提供更好的结果。

于 2017-04-20T08:27:13.933 回答