4

,Android支持从1.6版起向前的声明。根据官方网站,Android前瞻性声明不适用于1.6

在的manifest.xml已经调整了分SDK和目标SDK要求都为“4”,从蚀布局编辑器仍抱怨在一个相对布局未知的声明:

<xml> 

<CheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/ChkBoxSaveuser" 
    android:text="@string/options_saveuser" 
    android:layout_above="@id/ChkBoxSavePwd" 
    android:layout_marginTop="20dp" 
    android:layout_alignLeft="@id/EditTxtServer"/> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/EditTxtServer" 
    android:maxLines="1" 
    android:minWidth="200dp" 
    android:layout_marginTop="10dp" 
    android:layout_gravity="center_horizontal" 
    android:layout_above="@id/ChkBoxSaveuser"/> 

</xml> 

Multiple annotations found at this line:

  • ERROR Error: No resource found that matches the given name (at 'layout_above' with value '@id/ ChkBoxSavePwd').

  • ERROR Error: No resource found that matches the given name (at 'layout_alignLeft' with value '@id/EditTxtServer').

清洁/重建没有帮助..任何人都偶然发现此事?

回答

17

要使用向前引用,请在第一次使用引用时声明引用(使用“@ + id/...”表示法),而不要在实际元素上使用引用。

<xml> 

<CheckBox 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/ChkBoxSaveuser" 
    android:text="@string/options_saveuser" 
    android:layout_above="@+id/ChkBoxSavePwd" 
    android:layout_marginTop="20dp" 
    android:layout_alignLeft="@+id/EditTxtServer"/> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@id/EditTxtServer" 
    android:maxLines="1" 
    android:minWidth="200dp" 
    android:layout_marginTop="10dp" 
    android:layout_gravity="center_horizontal" 
    android:layout_above="@id/ChkBoxSaveuser"/> 

</xml> 
相关问题