is an array container for storing recovery obtainstyledattributes (AttributeSet, int[], int, int) or values, and obtainAttributes(AttributeSet, int[]) must call the Recycle () method when the operation is complete. The index value used to retrieve the Obtainstyledattributes property in the corresponding position of the structure.
To use this class, create a: Atts.xml file under the Valuse folder:
[HTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <resources>
- <declare-styleable name="Flowindicator">
- <attr name="Count" format="integer" />
- <attr name="Space" format="Dimension" />
- <attr name="point_size" format="Dimension" />
- <attr name="Point_seleted_color" format="color|reference" />
- <attr name="Point_normal_color" format="color|reference" />
- <attr name="Point_radius" format="Dimension" />
- </declare-styleable>
- </Resources>
First, declare the custom <declare-styleable name= "Flowindicator" >,nameflowindicator, set the property to a simpler format, the preceding parameter name, followed by the parameter format.
The format of a custom attribute can be as follows:
- Reference
- String
- Color
- Dimension
- Boolean
- Integer
- Float
- Fraction
- Enum
- Flag
Then use this:
[Java]View Plaincopy
- Public Flowindicator (context context, AttributeSet Attrs) {
- Super (context, attrs);
- //Get examples
- TypedArray Typearray = context.obtainstyledattributes (Attrs,
- R.styleable.flowindicator);
- //Get the corresponding value from Typearray, the second parameter is the default value, as the first parameter is not defined in Atts.xml, returns the second parameter value
- Count = Typearray.getinteger (R.styleable.flowindicator_count, 4);
- Space = Typearray.getdimension (R.styleable.flowindicator_space, 9);
- Radius = typearray.getdimension (R.styleable.flowindicator_point_radius, 9);
- Point_normal_color = Typearray.getcolor (
- R.styleable.flowindicator_point_normal_color, 0x000000);
- Point_seleted_color = Typearray.getcolor (
- R.styleable.flowindicator_point_seleted_color, 0xffff07);
- int sum = Attrs.getattributecount ();
- if (constans.debug) {
- String str = "";
- For (int i = 0; i < sum; i++) {
- String name = Attrs.getattributename (i);
- String value = Attrs.getattributevalue (i);
- str + = "Attr_name:" + name + ":" + value + "\ n";
- }
- LOG.I ("attribute", str);
- }
- Typearray.recycle ();
- }
Finally, be sure not to forget Typearray.recycle ():
[Java]View Plaincopy
- Give back a previously retrieved styledattributes, for later re-use.
Give back the previously extracted styledattributes, and then use it later.
It should be noted that the Flowindicator_count in the R.styleable.flowindicator_count used when acquiring the property is the format of the name _ property taken.
Once you have defined the custom properties, you can set the properties in the custom control:
[HTML]View Plaincopy
- <? XML version= "1.0" encoding="Utf-8"?>
- <framelayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="Http://schemas.android.com/apk/res/com.dream.myqiyi"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <com.dream.myqiyi.widget.FlowIndicator
- android:id="@+id/myview"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_marginbottom="5dip"
- app:count="4"
- android:gravity="center"
- app:point_normal_color="#45000000"
- app:point_radius="3dip"
- app:point_seleted_color="#ffffff"
- app:point_size="5dip"
- app:space="10dip" />
- </framelayout>
First, make a statement:
Xmlns:app= "Http://schemas.android.com/apk/res/com.dream.myqiyi", "Com.dream.myqiyi" This is the package name of your project.
Then we can use the app: This sets the custom properties.
[HTML]View Plaincopy < param name= "wmode" value= "Transparent" >
- app:point_ Normal_color= "#45000000" &NBSP;&NBSP;
- app:point_radius= "3dip" &NBSP;&NBSP;
- app: Point_seleted_color= "#ffffff" &NBSP;&NBSP;
- app:point_size=" 5dip "&NBSP;&NBSP;
- app:space= "10dip"
Android Custom View properties (Atts.xml,typedarray) Learning