【问题标题】:android eclipse error:Error: no resource found that matches the given name (at 'text' with value '@string/red')android eclipse错误:错误:找不到与给定名称匹配的资源(在'text',值为'@string/red')
【发布时间】:2011-08-30 04:17:36
【问题描述】:

这肯定让我有点发疯,因为我实际上是在学习 android 的教程之一,我已经遇到了一对问题。

首先,当我应用 android:gravity="center" 时,文本仅垂直居中而不是水平居中,如果我更改 helloworld 示例 textview android:text="@string/red" 然后转到 strings.xml 并将默认值更改为 <string name="red">redflashlight</string> 图形布局将文本显示为 @string/red 而不是 "redflashlight"

这令人担忧,因为我实际上是在按照视频教程进行操作,并且我正在做作者正在做的事情,我担心这可能是 sdk 或 eclipse 的问题?也许我的操作系统是vista?我真的不知道,任何帮助都会非常感谢。

这是我的 main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>    
<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/red"
/>
</LinearLayout>

这是我的strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="red">redflashlight</string>
<string name="app_name">simple flashlight</string>
</resources>

【问题讨论】:

  • 您是否将 main.xml 放在“res/layout”中,将 strings.xml 放在“res/values”文件夹中?
  • 是的,两者都位于 res 文件夹下的正确文件夹中,但问题仍然存在,默认的 hello world 示例很好,但是当我更改变量名时不起作用:/跨度>
  • 我可能已经发现这个教程似乎已经过时了,我很抱歉!

标签: java android eclipse android-2.2-froyo


【解决方案1】:

要使文本在垂直和水平方向居中,

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
><TextView  
android:gravity="center_horizontal"
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/red"
/></LinearLayout>

我尝试了您的代码并使其正常工作。我认为您的项目没有正确构建。所以,构建它: Project->从eclipse的菜单栏自动构建。

【讨论】:

  • 我没有手动键入 xml,而是使用了 android 资源 UI,它确实有效,这似乎是前进的方向!
猜你喜欢
  • 2020-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-19
  • 1970-01-01
相关资源
最近更新 更多