ViewGroup

方法:

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
//测量子布局困难的部分:指出测量说明并将它传递给特定的子布局。这个方法为子布局的一种尺寸(高或者宽)指出了正确的测量说明。目标是从我们得的子布局的参数里面结合一些信息得到最可能的结果。例如,如果这个视图知道它自己的参数(因为它的MeasureSpec有一个(精确地)EXACTLY模式),并且子布局已经在它的参数里面表明了它需要和它的父布局同样的尺寸,父布局需要询问子布局去以确切的大小布局。

//参数:

//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),并且以正确的方式像这个方法一样使用它需要实现那个方法。事件将以下面的顺序被接受:
  1. You will receive the down event here.//你将在这里收到按下的事件.
  2. 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.
  3. 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().
  4. If you return true from here, you will not receive any following events: the target view will receive the same event but with the actionACTION_CANCEL, and all further events will be delivered to your onTouchEvent() method and no longer appear here.
2//

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值