Android Resource Files

Source: Internet
Author: User
Tags dashed line

Code and resource Separation principle: easy to maintain and modify
Shape: Define graphics selector: Load different color or drawablelayer-list according to different situations: overlay from bottom to top

Resource files are:/res/drawable (graphics resource and frame animation. xml),/res/layout (Interface layout Resource),/res/values (various data sources, eg:strings, colors, dimens etc)
/res/menu (Menu layout Resource),/res/anim (animation resource ' tweened animation '),/res/raw (Raw resource eg:*.txt, *.mp3 etc)
/res/animator (Property animation Resource),/res/xml (XML resource file)

Common Files under the values folder are:
Strings.xml arrays.xml (Array) colors.xml dimens.xml (size) drawables.xml styles.xml (style) Themes.xml (theme)

These resource files are referenced in Java in the following ways:
Getresources (). getString (r.string.xx); Other resource references are similar

For colors: #000000, primary color (RGB), ARGB
#RGB three-bit 16 binary, e.g. #00f
#RRGGBB six-bit 16 binary, e.g. #7700ff
#ARGB four-bit color values with transparency, such as #f00f
#AARRGGBB eight-bit color values with transparency, such as #7700ff00

Dimensions: Pixel px, point pt, density independent pixel (DPI) DP, proportional independent pixel SP
Official recommendation: Control size DP, font size SP
Size conversion: PX to DP (DIP):D p = pxvalue/scale + 0.5f

Common Image Resource type: Portable Network image. PNG Other: 9-grid stretched image. 9.png *.jpg *.jpeg. gif

Animations are divided into three categories: Anim (view animation), animator (property animation), animatordrawable (frame animation) animation-list
Anim:alpha (gradient transparency), scale (gradient dimension stretch), translate (picture shift position Movement), rotate (picture transfer rotation)
Javacode: alphaanimation etc.tweened Animation (gradient animation) frame by frame (picture conversion)

Folders that are not subject to the Android platform:/assets
Assetmanager assets = getassets (); Assets.open (FileName);

***************
Android Shape uses:
Properties of shape: Rectangle, oval, line, ring (rectangle, ellipse, linear shape, ring)
The following properties are available only when shape=ring:
Innerradius Inner ring radius innerradiusratio floating point, with ring width ratio to represent inner ring radius
The thickness of the thickness ring is thicknessratio floating point, and the thickness of the ring is expressed as the width ratio of the ring
Uselevel if it is levellistdrawable use the value is true, otherwise false
When shape=ring: Must be uselevel=false;


Shape6 species Tags: corners, gradient, padding, size, solid, stroke
Solid and gradient cannot be used at the same time? Do they affect each other?
Corners (Fillet): radius (radius of all rounded corners) cannot be shared with other properties
Gradient (gradient):
Property: Type=[linear|radial|sweep] Gradient type: linear gradient (default) | Radial Gradient | scanned gradient
angle=45 gradient angle, multiples of 45 0 from left to right 90 top to bottom, only valid for linear gradients
CenterX CenterY The relative position of the center point of the gradient, in the range: 0~1, only when the radiation gradient is active
StartColor Centercolor EndColor
Gradientradius=5 the radius of the gradient to be used only when type=radial
Uselevel=true|false is used to specify whether the shape is to be used as a levellistdrawable, and the default value is False
Solid (inner fill color): Only one property color
Stroke (Stroke property): Width, color, dashwidth, dashgap after the two properties set the dashed line: wide (value is 0 o'clock solid) and interval (value is dimension)
Size, padding: Graphic size, internal margin (basic not used)

****************
Android Selector using:
Selector divided into two kinds: color-selector, drawable-selector
When used as a drawable resource, placed under Drawable, item is specified as Drawable property, and when used as a color resource, it is placed under/res/color, and item specifies the property: color
The item Android:drawable property can reference @color color values in addition to @drawable resources, but Android:color can only refer to @color;
Item is matched from top to bottom, and if it matches to an item then it will take this item instead of the rule with the best match
Set the default state, be sure to write at the end, if written in front, then all of the subsequent item will not work
<!--by default--
<item android:color= "@android: Color/white"/>
Under the Selector tab:
The fade-in time, in milliseconds, when the new state is displayed when the Android:enterfadeduration state changes
The fade-out time, in milliseconds, when the old state disappears when the android:exitfadeduration state changes

Android:state_enabled: Sets whether touch or click events are available, typically set only when false to indicate an unavailable state
Android:state_pressed: Sets whether to press the state, usually sets the property when True, indicates the pressed state, default to False
Android:state_selected: Sets whether the state is selected, True indicates checked, false indicates unchecked
Android:state_checked: Set check status, mainly used for checkbox and radiobutton,true indication has been checked, false means not checked
Android:state_checkable: Set tick if available status, similar to state_enabled, just state_enabled will affect touch or click events, and state_checkable affect tick events
Android:state_focused: Sets whether to get the focus state, true to get focus, default to False to indicate no focus
Android:state_window_focused: Sets whether the current window receives the focus state, True indicates the focus, false indicates that there is no focus, such as pulling down the notification bar or Popup dialog box, the current interface loses focus; The ListItem of the ListView also triggers the true state when it gets focus, which can be understood as the current window is the ListItem itself
Android:state_activated: The setting is activated, True indicates that it is active, false means inactive, API level 11 and above are supported, and the control's setactivated (Boolean) can be called through code method to set whether the control is activated
Android:state_hovered: Sets whether the mouse is sliding above the state, true indicates that the mouse is sliding above, the default is False,api level 14 and above to support


About the ListItem style of the ListView, there are two settings, one is to set the Android:listselector property in the ListView tab, and the other is to set up Android in ListItem layout layouts: Background However, the results of these two settings are different. At the same time, there are other areas to note when using the ListView, as summarized below:

Android:listselector set ListItem default background is transparent, no matter how you set in the selector can not change its background. Therefore, if you want to change the default background of ListItem, only in the second way, in the layout of ListItem layouts Android:background set.
When touch ListItem is clicked, the first setting, state_pressed, state_focused, and state_window_focused are set to true, and the second setting means only State_ Pressed will trigger.
When a control such as a button or a checkbox is in the ListItem, the focus of the ListItem itself is preempted, causing the touch-click event of the ListItem itself to be invalid. So, to solve this problem, there are three kinds of solutions:

Change a button or checkbox to a control such as TextView or ImageView
Set the Focusable property to False for control settings such as button or checkbox
Set ListItem root Layout properties android:descendantfocusability= "Blocksdescendants"
The third is the most convenient and recommended way to set all child controls under the ListItem root layout to not get the focus. There are three values for the Android:descendantfocusability property, where ViewGroup refers to the view that sets the property, in this case the root layout of ListItem:

Beforedescendants:viewgroup takes precedence over its subclass control and gets to focus
Afterdescendants:viewgroup gets focus only if its subclass control does not need to get focus
Blocksdescendants:viewgroup overrides the subclass control and gets the focus directly

*********************
Use of Layer-list:
Paddingmode=nest|stack
Item is superimposed from bottom to top, that is, the item defined first is below, followed by stacking
Offset at top of Android:top
Offset at bottom of android:bottom
Android:left offset to the left
Offset to the right of the Android:right

Android Resource Files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.