如何在Android studio的布局文件中设置自定义命名空间?

wal*_*len 14 xml android namespaces android-layout android-studio

我正在为我的项目使用dragsortlistview库,它需要在XML文件中使用自定义命名空间才能对其进行自定义.

mylayout.xml:

<com.mobeta.android.dslv.DragSortListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:dslv="http://schemas.android.com/apk/res-auto"
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="40dp"
    android:layout_marginRight="40dp"
    android:dividerHeight="10dp"
    android:divider="@color/light_grey"
    android:background="@color/light_grey"
    dslv:collapsed_height="2dp"
    dslv:drag_enabled="true"
    dslv:drag_handle_id="@drawable/drag_handle"
    dslv:drag_scroll_start="0.33"
    dslv:drag_start_mode="onMove"
    dslv:float_alpha="0.6"
    dslv:max_drag_scroll_speed="0.5"
    dslv:remove_enabled="true"
    dslv:remove_mode="flingRemove"
    dslv:slide_shuffle_speed="0.3"
    dslv:sort_enabled="true"
    dslv:track_drag_sort="false"
    dslv:use_default_controller="true"
    />
Run Code Online (Sandbox Code Playgroud)

当我创建这个项目时,我会为dslv命名空间中的每个属性得到这样的错误:

Gradle: No resource identifier found for attribute 'collapsed_height' in package 'net.mypackage'
Run Code Online (Sandbox Code Playgroud)

如何在Android Studio中使用自定义命名空间?

Geo*_*its 11

res-auto使用当前包名称,而不是库包名称.在您的情况下,它转换为net.mypackage.

如果要使用库的命名空间,则需要使用其包名.从类名来看,您正在使用此处的DSLV库.所以,你会想要使用:

xmlns:dslv="http://schemas.android.com/apk/res/com.mobeta.android.dslv" 
Run Code Online (Sandbox Code Playgroud)

  • 当我这样做时,Android Studio弹出错误并告诉我使用res-auto.但res-auto无法构建:/ (4认同)