Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

xml - How can I set up custom namespaces in layout file in Android studio?

I am using the dragsortlistview library for my project which requires the usage of a custom namespace in the XML file in order to customize it.

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"
    />

When I make this project I get errors like this for every attribute in the dslv namespace:

Gradle: No resource identifier found for attribute 'collapsed_height' in package 'net.mypackage'

How can I use custom namespace in Android Studio?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

res-auto uses the current package name, not the library package name. In your case, it translates to net.mypackage.

If you want to use the namespace for a library, you need to use its package name. Judging from the class name, you are using the DSLV library from here. So, you'll want to use:

xmlns:dslv="http://schemas.android.com/apk/res/com.mobeta.android.dslv" 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...