gpt4 book ai didi

android - 努力使用 MvvmCross 在 MvxImageView 中绑定(bind)本地镜像

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:09:07 24 4
gpt4 key购买 nike

我似乎无法在 MvxListView 中正确绑定(bind)图像

这是模板:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Mvx.MvxImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="10dp"
local:MvxBind="ImageUrl IconName, Converter=IconSource" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
local:MvxBind="Text Name" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="20dp"
local:MvxBind="Text Description" />
</LinearLayout>
</LinearLayout>

这是转换器:

public class IconSourceValueConverter : MvxValueConverter<string, string>
{
protected override string Convert(string value, Type targetType, object parameter, CultureInfo culture)
{
//string retval = string.Format("res:{0}", value.ToLower());
string retval = string.Format("@drawable/{0}", value.ToLower());
return retval;
}
}

所有图像都存在于 Drawable 文件夹中。

我尝试了 drawable 和 res,但都不起作用。

我用包含硬编码 android:src 的普通 ImageView 替换了 MvxImageView,它工作正常。

有什么想法吗?

最佳答案

我已经用它来让它为我工作:

public class StringToIntValueConverter : MvxValueConverter<string, int>
{
protected override int Convert(string value, Type targetType, object parameter, CultureInfo culture)
{
int image = 0;
if(value == "song")
image = Resource.Drawable.icon_category_song;

return image;
}
}

要在 Android 布局中使用它:

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:MvxBind="DrawableId StringToInt(Type)" />

在此示例中,“Type”是一个包含单词“song”的字符串。

关于android - 努力使用 MvvmCross 在 MvxImageView 中绑定(bind)本地镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22395347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com