2011-08-30 51 views
1

这肯定会让我有点疯狂,因为我真的在学习android和教程之一我已经遇到了一对问题。android eclipse错误:错误:找不到与给定名称匹配的资源(在'文本'中,值为'@ string/red')

首先是,当我申请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> 
+1

您是否已将main.xml放置在“res/values”文件夹的“res/layout”和strings.xml中? –

+0

是都在正确的文件夹坐在res文件夹下,但问题仍然存在,与默认hello世界的例子很好,但然后不工作时,我改变变量名称:/ –

+1

我可能已经想通了它出现本教程已过时我的道歉! –

回答

0

要在这两个文本中心垂直和水平,

<?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> 

我尝试你的代码并正常工作。我认为你的项目构建不当。所以,建立它: 项目 - >从Eclipse的菜单栏自动生成。

+0

取而代之的是手动键入xml,我使用了android资源UI来代替它并且工作,这似乎是前进的方向! –

相关问题