自定义控件中取出自定义属性的方法

public XXXLayout(Context context, AttributeSet atts) {
        super(context, attrs);
        //取出自定义属性
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.XXXLayout);
        mPicRatio = typedArray.getFloat(R.styleable.XXXLayout_picRatio, 1);
        mRelative = typedArray.getInt(R.styleable.XXXLayout_relative, RELATIVE_WIDT);
        typedArray.recycle();
}

你可能感兴趣的:(自定义控件中取出自定义属性的方法)