일부 Android 레이아웃에서는 사용자 지정 특성을 사용하려고하지만 android:
이외의 네임 스페이스 접두사를 사용하려고하면 Eclipse에서 오류가 발생합니다. 자식 요소. 자식 요소가 아닌 파일의 루트/부모 요소에 custom:
네임 스페이스 접두사를 사용하면 제대로 작동합니다.레이아웃의 자식 요소에 비 안드로이드 네임 스페이스 접두사 사용
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
custom:my_tag1="whatever"> <!-- compiles fine -->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
custom:my_tag2="true"/> <!-- generates an error -->
</LinearLayout>
이클립스 (단지 custom:
접두사를 사용하는 초 시도에서) 준다 오류는 다음과 같습니다 :
예를 들어, 여기에 지정된 사용자 정의 네임 스페이스와 간단한 레이아웃입니다
ImageView 태그에 예기치 않은 네임 스페이스 접두사 "custom"이 있습니다.
은 내 루트 요소 대신 LinearLayout
의 ImageView
한 경우, 접두사가 허용됩니다. 그래서 그것은 단지 자식 요소의 네임 스페이스 접두어를 사용하는 것만 큼 문제가있는 것처럼 보입니다.
또한 xmlns:custom="http://schemas.android.com/apk/res-auto"
속성을 ImageView에 추가하려고하면 불만도 제기됩니다. 내가 할 수 있어야 수행 할 작업을 믿고 날 리드 몇 가지 물건을 온라인으로 본 적이
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="my_tag1" format="string"/>
<attr name="my_tag2" format="boolean"/>
</resources>
: 도움이된다면
, 여기에 내가 위로 사용하고있어 attrs.xml
파일입니다. 예를 들어, 수락 된 대답 here에서 Qberticus는 자식 클래스에 "whatever"라는 접두사를 사용합니다. 포스트 here에서도 마찬가지입니다.
나는 그것을 얻지 않는다. 자식 요소에 허용되지 않는 비 안드로이드 네임 스페이스 접두어를 사용하고 있습니까? 아니면 내가 잘못하고 있습니까?
해결책을 찾았습니까? –
@Xylian 불행히도, 아닙니다. 죄송합니다. 필자는 대신'styles.xml'에서 커스텀 속성을 사용하여 작업을 마무리했습니다. – Turix
도움이 될만한 정보가 있습니다. http://stackoverflow.com/questions/4568632/custom-attributes-in-android – Mehdiway