方法:
1.public static int getChildMeasureSpec (int spec, int padding, int childDimension)
Added in
API level 1
Does the hard part of measureChildren: figuring out the MeasureSpec to pass to a particular child. This method figures out the right MeasureSpec for one dimension (height or width) of one child view. The goal is to combine information from our MeasureSpec with the LayoutParams of the child to get the best possible results. For example, if the this view knows its size (because its MeasureSpec has a mode of EXACTLY), and the child has indicated in its LayoutParams that it wants to be the same size as the parent, the parent should ask the child to layout given an exact size.
Parameters
spec | The requirements for this view |
---|---|
padding | The padding of this view for the current dimension and margins, if applicable |
childDimension | How big the child wants to be in the current dimension |
Returns
- a MeasureSpec integer for the child
//参数:
//spec:这个视图的要求
//padding:如果可以,这个视图的填充为当前的尺寸和边缘。
//childDimension:在当前的尺寸上,子布局要求多大。
(2)
public boolean onInterceptTouchEvent (MotionEvent ev)..拦截
Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.
//拦截这个方法去拦截所有的屏幕移动事件。它允许你监视这些事件,当它们被分发到你的children时,并且在任何一点上获得当前手势的控制权。
Using this function takes some care, as it has a fairly complicated interaction with
View.onTouchEvent(MotionEvent)
, and using it requires implementing that method as well as this one in the correct way. Events will be received in the following order:
//使用这个函数要注意,如果它有一个相对复杂的交互和View.onTouchEvent(MotionEvent),并且以正确的方式像这个方法一样使用它需要实现那个方法。事件将以下面的顺序被接受:
- You will receive the down event here.//你将在这里收到按下的事件.
- The down event will be handled either by a child of this view group, or given to your own onTouchEvent() method to handle; this means you should implement onTouchEvent() to return true, so you will continue to see the rest of the gesture (instead of looking for a parent view to handle it). Also, by returning true from onTouchEvent(), you will not receive any following events in onInterceptTouchEvent() and all touch processing must happen in onTouchEvent() like normal.
- For as long as you return false from this function, each following event (up to and including the final up) will be delivered first here and then to the target's onTouchEvent().
- If you return true from here, you will not receive any following events: the target view will receive the same event but with the action
ACTION_CANCEL
, and all further events will be delivered to your onTouchEvent() method and no longer appear here.