2016-12-12 15 views
0

アンドロイドで作業している人は誰でもxml名前空間宣言xmlns:android = xmlns:android="http://schemas.android.com/apk/res/androidに精通していると確信しています。ここに私の質問があります。アンドロイドはxmlの要素のさまざまな属性をどのように認識しましたか?

上記の名前空間宣言が主に一意の識別にすぎない場合は、android:layout_widthandroid:layout_heightなどのすべての属性が正確にどこから来たのでしょうか?

xmlns:android="http://schemas.android.com/apk/res/androidがあらかじめ定義された属性を含むスキーマの場合は、これらすべての属性を変更することができます。その場合、このスキーマはどこに格納されていますか?

私は自分の投稿が潜在的に重複する投稿であるかどうかを確認するために上記のリンクを見ましたが、そうではありません。他の投稿は、基本的にはxmlns:android="http://schemas.android.com/apk/res/androidが何をしているかを示しています。しかし、私はすでに、その名前空間宣言の機能が何であるかを知っています。私の関心事は、上記の名前空間が何もない場合、どの要素がそれぞれの要素にどのような属性があるのか​​、アンドロイドはどうしているのでしょうか?少なくとも私は上記の名前空間は何も参照されていないと思う。

+0

[Android xmlnsについて](http://stackoverflow.com/questions/19020171/regarding-android-xmlns) –

+0

の複製について[複数の類似の質問がありました](http:// stackoverflow。 com/search?q =%22xmlns%3Aandandroid%22)。少なくとも私が見つけた明確な答えはありませんでした。あなたが求めていることは、ここで非常に明確に文書化されています。 https://developer.android.com/guide/topics/resources/layout-resource.html –

+0

これらの回答は「URIではなくURL」と表示されます。つまり、あなたはそのアドレスにブラウザを使用して、結果が返されることを期待してください –

答えて

1

名前空間は何も参照しません。プルする属性を知る必要があります。

ここには、ViewGroupのAndroidソースコードのスニペットがあります。

<declare-styleable name="ViewGroup_Layout"> 
    <!-- Specifies the basic width of the view. This is a required attribute 
     for any view inside of a containing layout manager. Its value may 
     be a dimension (such as "12dip") for a constant width or one of 
     the special constants. --> 
    <attr name="layout_width" format="dimension"> 
     <!-- The view should be as big as its parent (minus padding). 
      This constant is deprecated starting from API Level 8 and 
      is replaced by {@code match_parent}. --> 
     <enum name="fill_parent" value="-1" /> 
     <!-- The view should be as big as its parent (minus padding). 
      Introduced in API Level 8. --> 
     <enum name="match_parent" value="-1" /> 
     <!-- The view should be only big enough to enclose its content (plus padding). --> 
     <enum name="wrap_content" value="-2" /> 
    </attr> 
    <!-- Specifies the basic height of the view. This is a required attribute 
     for any view inside of a containing layout manager. Its value may 
     be a dimension (such as "12dip") for a constant height or one of 
     the special constants. --> 
    <attr name="layout_height" format="dimension"> 
     <!-- The view should be as big as its parent (minus padding). 
      This constant is deprecated starting from API Level 8 and 
      is replaced by {@code match_parent}. --> 
     <enum name="fill_parent" value="-1" /> 
     <!-- The view should be as big as its parent (minus padding). 
      Introduced in API Level 8. --> 
     <enum name="match_parent" value="-1" /> 
     <!-- The view should be only big enough to enclose its content (plus padding). --> 
     <enum name="wrap_content" value="-2" /> 
    </attr> 
</declare-styleable> 

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/attrs.xml#3005

Androidはdefining custom attributes for your custom Viewクラスよりも異なる属性は、各要素のためにそこにあるか

を知らないんどのように、それはSDK内に配置されているres/values/attrs.xmlから引っ張ります。

ここでセクションを参照してください。

カスタム属性を定義したら、組み込み属性のようにレイアウトXMLファイルでカスタム属性を使用できます。唯一の違いは、カスタム属性が別の名前空間に属していることです。代わりにhttp://schemas.android.com/apk/res/android名前空間に属するの、彼らはhttp://schemas.android.com/apk/res/[your package name]

に属しているので、androidは組み込み属性のためだけの名前空間です。

+0

これは私が探していたものです。しかし、私が理解していない簡単な部分です。 res/values/atttrs.xmlは "http://schemas.android.com/apk/res/android"のどこにも収まらないようです。 res/values!= res/androidという事実のために私はちょっと変わったですが、あなたは依然として属性を参照することができます。この部分について少し精巧に考えていらっしゃいますか? – Wowzer

+0

Javaからリソースにアクセスするための 'your.package.name.R'があります。次に、SDKリソースにアクセスするための' android.R'があります。それはXMLと同じコンセプトです。 'res/[あなたのパッケージ名]' == 'your.package.name.R'と' res/android' == 'android.R' –

+0

ああああああ、res/android == android.Rだけど、場合は、私はres/android/attr宣言スタイルの属性を参照する必要がありますか? – Wowzer

関連する問題