首页 > 解决方案 > SwipeLayout - 无法解析 attr.xml 中的符号“drag_edge”

问题描述

我试图了解我错过了什么。我在构造函数中有下一行的 SwipeLayout 类的实现:

public SwipeLayout(Context context, AttributeSet attrs, int defStyle) {
    ...
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeLayout);
    int dragEdgeChoices = a.getInt(R.styleable.SwipeLayout_drag_edge, DRAG_RIGHT);
    mEdgeSwipesOffset[DragEdge.Left.ordinal()] = a.getDimension(R.styleable.SwipeLayout_leftEdgeSwipeOffset, 0);
    mEdgeSwipesOffset[DragEdge.Right.ordinal()] = a.getDimension(R.styleable.SwipeLayout_rightEdgeSwipeOffset, 0);
    mEdgeSwipesOffset[DragEdge.Top.ordinal()] = a.getDimension(R.styleable.SwipeLayout_topEdgeSwipeOffset, 0);
    mEdgeSwipesOffset[DragEdge.Bottom.ordinal()] = a.getDimension(R.styleable.SwipeLayout_bottomEdgeSwipeOffset, 0);
    setClickToClose(a.getBoolean(R.styleable.SwipeLayout_clickToClose, mClickToClose));
    ...
}

并有一个带有样式值的 attr.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SwipeLayout">
    <attr name="drag_edge">
        <flag name="left" value="1" />
        <flag name="right" value="2" />
        <flag name="top" value="4" />
        <flag name="bottom" value="8" />
    </attr>
    <attr name="leftEdgeSwipeOffset" format="dimension" />
    <attr name="rightEdgeSwipeOffset" format="dimension" />
    <attr name="topEdgeSwipeOffset" format="dimension" />
    <attr name="bottomEdgeSwipeOffset" format="dimension" />
    <attr name="show_mode" format="enum">
        <enum name="lay_down" value="0" />
        <enum name="pull_out" value="1" />
    </attr>
    <attr name="clickToClose" format="boolean" />
</declare-styleable>
</resources>

但这是 xml 中的一个错误,它告诉我找不到像“drag_edge”、“leftEdgeSwipeOffset”、“rightEdgeSwipeOffset”等名称。也许我错过了一些支持或设计库?

标签: androidattrdeclare-styleablestyleable

解决方案


推荐阅读