这确实让我有点疯狂,因为我正在学习 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>
最佳答案
使文本垂直和水平居中,
<?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 的菜单栏中选择“项目”->“自动构建”。
关于java - android eclipse错误:Error: no resource found that matches the given name (at 'text' with value '@string/red' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7238630/