0

Android で属性を持つカスタム要素を作成する場合、アプリケーションの名前空間をレイアウトに配置する必要があります。

例えば:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:whatever="http://schemas.android.com/apk/res/org.example.mypackage"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

    <org.example.mypackage.MyCustomView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      whatever:my_custom_attribute="Hello, world!" />
</LinearLayout>

これには、例のように、Eclipse でのプロジェクトの構造が、マニフェストで定義されている Android パッケージの名前と同じである必要もありますか? これもうまくいきますか:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:whatever="http://schemas.android.com/apk/res/org.mycompany.myproduct"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

    <org.example.mypackage.MyCustomView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      whatever:my_custom_attribute="Hello, world!" />
</LinearLayout>
4

1 に答える 1

1

反映する必要があるアプリケーションのパッケージ名です。したがって、あなたが行っているように使用するのは正しいです。

例えば:

xmlns:whatever="http://schemas.android.com/apk/res/org.mycompany.myproduct最後の部分はパッケージ名org.mycompany.myproductと同じである必要があります。また、次のように変更することもできますが、xml の属性のプレフィックスとして使用するようにしてください。xmlns:whateverxmlns:theblitztheblitz

詳細については、こちらをお読みください

于 2012-05-13T10:29:17.897 に答える