传承者(Inheritors)打造共同进步生态圈!!!
关于AttributeSet
它是一个接口
/**
* A collection of attributes, as found associated with a tag in an XML
* document. Often you will not want to use this interface directly, instead
* passing it to {@link android.content.res.Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)
* Resources.Theme.obtainStyledAttributes()}
* /
部分方法摘抄
public interface AttributeSet {
/**
* Returns the number of attributes available in the set.
*
* @return A positive integer, or 0 if the set is empty.
*/
public int getAttributeCount();
/**
* Returns the name of the specified attribute.
*
* @param index Index of the desired attribute, 0...count-1.
*
* @return A String containing the name of the attribute, or null if the
* attribute cannot be found.
*/
public String getAttributeName(int index);
/**
* Returns the value of the specified attribute as a string representation.
*
* @param index Index of the desired attribute, 0...count-1.
*
* @return A String containing the value of the attribute, or null if the
* attribute cannot be found.
*/
public String getAttributeValue(int index);
/**
* Returns the value of the specified attribute as a string representation.
* The lookup is performed using the attribute name.
*
* @param namespace The namespace of the attribute to get the value from.
* @param name The name of the attribute to get the value from.
*
* @return A String containing the value of the attribute, or null if the
* attribute cannot be found.
*/
.......
}
关于TypedArray,部分方法摘抄
/**
* Container for an array of values that were retrieved with
* {@link Resources.Theme#obtainStyledAttributes(AttributeSet, int[], int, int)}
* or {@link Resources#obtainAttributes}. Be
* sure to call {@link #recycle} when done with them.
*
* The indices used to retrieve values from this structure correspond to
* the positions of the attributes given to obtainStyledAttributes.
*/
public class TypedArray {
.......
/**
* Return the number of indices in the array that actually have data.
*
* @throws RuntimeException if the TypedArray has already been recycled.
*/
public int getIndexCount() {
if (mRecycled) {
throw new RuntimeException("Cannot make calls to a recycled instance!");
}
return mIndices[0];
}
/**
* Returns an index in the array that has data.
*
* @param at The index you would like to returned, ranging from 0 to
* {@link #getIndexCount()}.
*
* @return The index at the given offset, which can be used with
* {@link #getValue} and related APIs.
* @throws RuntimeException if the TypedArray has already been recycled.
*/
public int getIndex(int at) {
if (mRecycled) {
throw new RuntimeException("Cannot make calls to a recycled instance!");
}
return mIndices[1+at];
}
......