2011-08-30 48 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來代替它並且工作,這似乎是前進的方向! –

相關問題