2011-01-23 17 views
38

アンドロイドレイアウトxmlファイルの "android:"と "@android:"の違いは何ですか?彼らはAndroid SDKのリソースを再利用する交換可能な方法のようです。アンドロイドレイアウトxmlファイルの "android:"と "@android:"の違いは何ですか?

私が発見した唯一の違いは、次の例で説明されています。

ここでのTextViewの右端は、ここでのImageButton

<RelativeLayout 
    android:id="@id/header" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#888888"> 
    <TextView 
     android:id="@android:id/text1" 
     android:layout_alignParentLeft="true" 
     android:text="blah blah" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@android:id/button1" /> 
    <ImageButton 
     android:id="@android:id/button1" 
     android:layout_alignParentRight="true" 
     style="@style/PlusButton" /> 
</RelativeLayout> 

の左端と整列レンダリングされ、但し、のTextViewの右端はRelativeLayoutの右端に位置合わせされます。 TextViewはImageButtonと重なっています。

<RelativeLayout 
    android:id="@id/header" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#888888"> 
    <TextView 
     android:id="@android:id/text1" 
     android:layout_alignParentLeft="true" 
     android:text="blah blah" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="?android:id/button1" /> 
    <ImageButton 
     android:id="?android:id/button1" 
     android:layout_alignParentRight="true" 
     style="@style/PlusButton" /> 
</RelativeLayout> 

2つのレイアウトの唯一の違いは、@ android対?androidの使用です。どちらもエラーなしでコンパイルされます。

ありがとうございました。

+0

可能な複製を(http://stackoverflow.com/questions/2733907/question-mark-in- xml-attributes-for-android) –

答えて

33

IDの前に疑問符を付けると、属性をハードコードするのではなく、スタイルテーマで定義されているスタイル属性にアクセスすることを示します。

を参照してくださいここでは "の参照スタイル属性":[(?)のAndroid用XML属性で疑問符]のaccessing-resources

+4

より具体的には、?余分なレベルの間接参照を意味します。それを、属性自体を参照するのではなく、指すリソースをフェッチするテーマ属性を逆参照すると考えてください。 '?android:attr/foo'でこれを見ることができます。 – adamp

+7

私はこの回答に多くの説明があることを望みます – CodyBugstein

+0

@Imray、ここに例があります:sdk \ platforms \ android-L \ data \ res \ valuesにあるthemes.xmlファイルからこれらのスタイルが見つかりました。アンドロイド@ '<スタイル名= "テーマ"> <項目名= "colorForeground">​​:カラー/ bright_foreground_dark ' 項目は <スタイル名= "Theme.Holo"> <項目名= "colorForeground">​​をbright_foreground_light同じディレクトリにあるattrs.xmlファイルのformat = "color" /> – chjarder

関連する問題