标签:android des style http java color
The basic cycle of a view is as follows:
requestLayout()
.invalidate()
.requestLayout()
or
invalidate()
were called, the framework will take care of measuring, laying out, and drawing the tree as appropriate.The geometry of a view is that of a rectangle. A view has a location, expressed as a pair of left and top coordinates, and two dimensions, expressed as a width and a height. The unit for location and dimensions is the pixel.
It is possible to retrieve the location of a view by invoking the methods
getLeft()
and getTop()
. The former returns the left, or X, coordinate of the rectangle representing the view. The latter returns the top, or Y, coordinate of the rectangle representing the view. These methods both return the location of
the view relative to its parent. For instance, when getLeft() returns 20, that means the view is located 20 pixels to the right of the left edge of
its direct parent.
In addition, several convenience methods are offered to avoid unnecessary computations, namely
getRight()
and getBottom()
. These methods return the coordinates of the right and bottom edges of the rectangle representing the view. For instance, calling
getRight()
is similar to the following computation: getLeft() + getWidth()
(see
Size for more information about the width.)
The size of a view is expressed with a width and a height. A view actually possess two pairs of width and height values.
The first pair is known as measured width and measured height. These dimensions define how big a view wants to be within its parent (see
Layout for more details.) The measured dimensions can be obtained by calling
getMeasuredWidth()
and getMeasuredHeight()
.
The second pair is simply known as width and height, or sometimes
drawing width and drawing height. These dimensions define the actual size of the view on screen, at drawing time and after layout. These values may, but do not have to, be different from the measured width and height. The width and height
can be obtained by calling getWidth()
and
getHeight()
.
To measure its dimensions, a view takes into account its padding. The padding is expressed in pixels for the left, top, right and bottom parts of the view. Padding can be used to offset the content of the view by a specific amount of pixels. For instance,
a left padding of 2 will push the view‘s content by 2 pixels to the right of the left edge. Padding can be set using the
setPadding(int, int, int, int)
or setPaddingRelative(int, int, int, int)
method and queried by calling
getPaddingLeft()
, getPaddingTop()
, getPaddingRight()
,
getPaddingBottom()
, getPaddingStart()
, getPaddingEnd()
.
Even though a view can define a padding, it does not provide any support for margins. However, view groups provide such a support. Refer to
android.view.ViewGroup
and android.view.ViewGroup.MarginLayoutParams
for further information.
Layout is a two pass process: a measure pass and a layout pass. The measuring pass is implemented in
measure(int, int)
and is a top-down traversal of the view tree. Each view pushes dimension specifications down the tree during the recursion. At the end of the measure pass, every view has stored its measurements. The second pass happens in
layout(int,int,int,int)
and is also top-down. During this pass each parent is responsible for positioning all of its children using the sizes computed in the measure pass.
When a view‘s measure() method returns, its getMeasuredWidth()
and
getMeasuredHeight()
values must be set, along with those for all of that view‘s descendants. A view‘s measured width and measured height values must respect the constraints imposed by the view‘s parents. This guarantees that at the end of the measure
pass, all parents accept all of their children‘s measurements.
A parent view may call measure() more than once on its children. For example, the parent may measure each child once with unspecified dimensions to find out how big they want to be, then call measure() on them again with
actual numbers if the sum of all the children‘s unconstrained sizes is too big or too small.
The measure pass uses two classes to communicate dimensions. The
MeasureSpec
class is used by views to tell their parents how they want to be measured and positioned. The base LayoutParams class just describes how big the view wants to be for both width and height. For each dimension,
it can specify one of:
There are subclasses of LayoutParams for different subclasses of ViewGroup. For example, AbsoluteLayout has its own subclass of LayoutParams which adds an X and Y value.
MeasureSpecs are used to push requirements down the tree from parent to child. A MeasureSpec can be in one of three modes:
To intiate a layout, call requestLayout
. This method is typically called by a view on itself when
it believes that is can no longer fit within its current bounds.
Drawing is handled by walking the tree and rendering each view that intersects the invalid region. Because the tree is traversed in-order, this means that parents will draw before (i.e., behind) their children, with siblings drawn in the order they appear
in the tree. If you set a background drawable for a View, then the View will draw it for you before calling back to its
onDraw()
method.
Note that the framework will not draw views that are not in the invalid region.
To force a view to draw, call
invalidate()
.
The basic cycle of a view is as follows:
requestLayout()
.invalidate()
.requestLayout()
or
invalidate()
were called, the framework will take care of measuring, laying out, and drawing the tree as appropriate.Note: The entire view tree is single threaded. You must always be on the UI thread when calling any method on any view. If you are doing work on other threads and want to update the
state of a view from that thread, you should use a Handler
.
//必须在UI线程中调用这2个方法
The framework will handle routine focus movement in response to user input. This includes changing the focus as views are removed or hidden, or as new views become available. Views indicate their willingness to take focus through the
isFocusable
method. To change whether a view can take focus, call
setFocusable(boolean)
. When in touch mode (see notes below) views indicate whether they still would like focus via
isFocusableInTouchMode
and can change this via setFocusableInTouchMode(boolean)
.
Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. In rare cases, the default algorithm may not match the intended behavior of the developer. In these situations, you can provide explicit overrides by using these XML attributes in the layout file:
nextFocusDown nextFocusLeft nextFocusRight nextFocusUp
To get a particular view to take focus, call requestFocus()
.
When a user is navigating a user interface via directional keys such as a D-pad, it is necessary to give focus to actionable items such as buttons so the user can see what will take input. If the device has touch capabilities, however, and the user begins interacting with the interface by touching it, it is no longer necessary to always highlight, or give focus to, a particular view. This motivates a mode for interaction named ‘touch mode‘.
For a touch capable device, once the user touches the screen, the device will enter touch mode. From this point onward, only views for which
isFocusableInTouchMode
is true will be focusable, such as text editing widgets. Other views that are touchable, like buttons, will not take focus when touched; they will only fire the on click listeners.
Any time a user hits a directional key, such as a D-pad direction, the view device will exit touch mode, and find a view to take focus, so that the user may resume interacting with the user interface without touching the screen again.
The touch mode state is maintained across android.app.Activity
s. Call
isInTouchMode
to see whether the device is currently in touch mode.
The framework provides basic support for views that wish to internally scroll their content. This includes keeping track of the X and Y scroll offset as well as mechanisms for drawing scrollbars. See
scrollBy(int, int)
, scrollTo(int, int)
, and awakenScrollBars()
for more details.
Unlike IDs, tags are not used to identify views. Tags are essentially an extra piece of information that can be associated with a view. They are most often used as a convenience to store data related to views in the views themselves rather than by putting them in a separate structure.
The View class exposes an ALPHA
property, as well as several transform-related properties, such as
TRANSLATION_X
and TRANSLATION_Y
. These properties are available both in the
Property
form as well as in similarly-named setter/getter methods (such as
setAlpha(float)
for ALPHA
). These properties can be used to set persistent state associated with these rendering-related properties on the view. The properties and methods can also be used in conjunction with
Animator
-based animations, described more in the
Animation section.
Starting with Android 3.0, the preferred way of animating views is to use the
android.animation
package APIs. These Animator
-based classes change actual properties of the View object, such as
alpha
and translationX
. This behavior is contrasted to that of the pre-3.0
Animation
-based classes, which instead animate only how the view is drawn on the display. In particular, the
ViewPropertyAnimator
class makes animating these View properties particularly easy and efficient.
Alternatively, you can use the pre-3.0 animation classes to animate how Views are rendered. You can attach an
Animation
object to a view using setAnimation(Animation)
or
startAnimation(Animation)
. The animation can alter the scale, rotation, translation and alpha of a view over time. If the animation is attached to a view that has children, the animation will affect the entire subtree rooted by that node. When
an animation is started, the framework will take care of redrawing the appropriate views until the animation completes.
闲来看看View.java的Developer Guides,布布扣,bubuko.com
闲来看看View.java的Developer Guides
标签:android des style http java color
原文地址:http://blog.csdn.net/leehu1987/article/details/35268911