如何在 Android Studio 的布局文件中设置自定义命名空间? [英] How can I set up custom namespaces in layout file in Android studio?

查看:67
本文介绍了如何在 Android Studio 的布局文件中设置自定义命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

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

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

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'

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

How can I use custom namespace in Android Studio?

推荐答案

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

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

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

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" 

这篇关于如何在 Android Studio 的布局文件中设置自定义命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆