我正在使用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" />
答案 0 :(得分: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
是deprecated)
如果您不希望图像以奇怪的方式拉伸,并且您无法保证传入图像的纵横比与布局的纵横比相匹配,则需要选择一个方面(宽度或高度)决定另一个的大小,使比率保持不变。您可以使用以下内容执行此操作(在这种情况下,您要确定宽度,并根据图像的宽高比计算宽度):
<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" />
在几乎所有无法保证缩放图像宽高比的情况下,第二个选项都会提供比第一个更好的结果。