2011-04-07 79 views
0

我是全新的eclipse和编程,我正在关注视频教程,但我无法弄清楚为什么我的eclipse不能识别编码。在视频中,我看到他补充说用eclipse编程,不能识别我在android中的android代码

android:gravity=center 
android:background="@color/red" 

它改变颜色,但我的不.. 的android:gravity变为粉红色和= ...变为蓝色,但矿一直是黑色,当我看在图形布局的代码没有注册

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

回答

2

这里是更正后的代码,

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

颜色也可以在XML文件中定义。 在/ res/values中创建一个新的xml文件名称color.xml。 以下代码粘贴到里面

<color name="red">#FF0000</color> 

另外,还要确保你在strings.xml中

<string name="red">Your text</string> 

以下行,并更改代码,如下所示。

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

非常感谢我意识到这是为“>” – user696087 2011-04-07 13:29:57

+0

ū[R欢迎... user696087简单的东西..ü有任何姓名或网名???这样称呼你似乎很难...... – 2011-04-07 17:43:38

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

这一点是错误的。它已在布局对象内声明。去掉它。

<TextView 
    android:layout_height="wrap_content" 
    android:text="@string/red" android:layout_width="wrap_content"/> 
</LinearLayout> 

您是否在字符串xml文件的资源文件夹中声明了红色的颜色?

Read