Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:如何从字符串设置ImageView src?_Android - Fatal编程技术网

Android:如何从字符串设置ImageView src?

Android:如何从字符串设置ImageView src?,android,Android,我是java的初学者,请帮忙。我有一个android应用程序源代码。我的默认图像视图如下所示: <ImageView android:id="@+id/flag_logo" android:layout_marginBottom="@dimen/global_keyline_s" android:scaleType="fitCenter" android:src="@drawable/flag_icon" an

我是java的初学者,请帮忙。我有一个android应用程序源代码。我的默认图像视图如下所示:

<ImageView
        android:id="@+id/flag_logo"
        android:layout_marginBottom="@dimen/global_keyline_s"
        android:scaleType="fitCenter"
        android:src="@drawable/flag_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:cropToPadding="false"
        android:adjustViewBounds="true" />

我一直在寻找此问题,但尚未找到,请帮助。谢谢。

在ImageVew中,我可以更改:

android:src=“@drawable/flag_icon”到android:src=“@string/flag_icon”

不,你不能。
@drawable/flag_图标
的意思是,drawable
flag_图标
位于
drawable
文件夹中。除非您有一个名为
字符串
,该路径在ImageVew中无效

,我可以更改:

android:src=“@drawable/flag_icon”到android:src=“@string/flag_icon”

不,你不能。
@drawable/flag_图标
的意思是,drawable
flag_图标
位于
drawable
文件夹中。除非您有一个名为
字符串
,该路径无效

我认为你的方法是个坏主意


您也可以本地化可拉伸的。我认为这是在本地化应用程序时更改图像的更好方法。

我认为你的方法是个坏主意


您也可以本地化可拉伸的。我认为这是在本地化应用程序时更改图像的更好方法。

就本地化而言,只能本地化某些特定的res文件夹。更多信息

对于drawable,您应该使用类似于
drawable-[language code]-r[capitalized localization code]
的东西


而且,由于数据值不匹配,您的方法将不起作用(读取不起作用)
@drawable
返回
int

就本地化而言,只能本地化某些特定的res文件夹。更多信息

对于drawable,您应该使用类似于
drawable-[language code]-r[capitalized localization code]
的东西


而且,由于数据值不匹配,您的方法将不起作用(读取不起作用)
@drawable
返回
int

就像@glethien建议的那样。我会使用本地化的抽绳-


因此,您将图像放在可绘制的hdpi和可绘制的de hdpi中,并根据设备语言使用适当的资源。

就像@glethien建议的那样。我会使用本地化的抽绳-


因此,您将图像放入可绘制hdpi和可绘制de hdpi中,并基于设备语言,这将需要适当的资源。

我有一个问题。为什么?您不能将imageview src更改为字符串src。Imageview src只不过是imagefile。android:src=“@drawable/flag_icon”是一个整数值,而您调用的是一个字符串值,问题是为什么?也许有解决方案?
在Imageview中,我可以将:android:src=“@drawable/flag_icon”更改为android:src=“@string/flag_icon”
否。事实上,它会给您一个错误:
意外的资源引用类型
。你可以改为使用资源名而不是它的id(这在某些有限的情况下很有用)。我有一个问题。为什么?您不能将imageview src更改为字符串src。Imageview src只不过是imagefile。android:src=“@drawable/flag_icon”是一个整数值,而您调用的是一个字符串值,问题是为什么?也许有解决方案?
在Imageview中,我可以将:android:src=“@drawable/flag_icon”更改为android:src=“@string/flag_icon”
否。事实上,它会给您一个错误:
意外的资源引用类型
。您可以改为使用资源名称而不是其id(这在某些有限的情况下很有用)
<resources>
    <string name="app_name">My App Name</string>
    <string name="flag_icon">@drawable/flag_icon</string>
    ...
</resources>
Error:(4) Error: Unexpected resource reference type; expected value of type @string/ [ReferenceType]