Android:子视图从Jelly Bean中的父视图共享压缩状态

时间:2013-01-06 04:53:09

标签: android view ontouchevent

代码评论: 1. RelativeLayout Clickable attr设置为true,其具有子视图,其Clickable attr设置为false。 2.没有任何duplicateParentState attr,换句话说,duplicateParentState为false。 3.子视图是TextView,其textColor是颜色选择器,因此它可以检查按下的状态。

行为: 在level16之前,当点击RelativeLayout时,按下的状态不会传输到他的chlid视图。 但是在16级或更高级别,它可以。

原因: setPressed ------> dispatchSetPressed ------>将按下的状态发送到子视图-----> childView.setPressed

第15级的View.java onTouchEvent,

case MotionEvent.ACTION_DOWN:
                mHasPerformedLongPress = false;

                if (performButtonActionOnTouchDown(event)) {
                    break;
                }

                // Walk up the hierarchy to determine if we're inside a scrolling container.
                boolean isInScrollingContainer = isInScrollingContainer();

                // For views inside a scrolling container, delay the pressed feedback for
                // a short period in case this is a scroll.
                if (isInScrollingContainer) {
                    mPrivateFlags |= PREPRESSED;
                    if (mPendingCheckForTap == null) {
                        mPendingCheckForTap = new CheckForTap();
                    }
                    postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
                } else {
                    // Not inside a scrolling container, so show the feedback right away
                    mPrivateFlags |= PRESSED; //comment by bran
                    refreshDrawableState();
                    checkForLongClick(0);
                }
                break;

16级的View.java onTouchEvent,

case MotionEvent.ACTION_DOWN:
                 mHasPerformedLongPress = false;

                 if (performButtonActionOnTouchDown(event)) {
                     break;
                 }

                 // Walk up the hierarchy to determine if we're inside a scrolling container.
                 boolean isInScrollingContainer = isInScrollingContainer();

                 // For views inside a scrolling container, delay the pressed feedback for
                 // a short period in case this is a scroll.
                 if (isInScrollingContainer) {
                     mPrivateFlags |= PREPRESSED;
                     if (mPendingCheckForTap == null) {
                         mPendingCheckForTap = new CheckForTap();
                     }
                     postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
                 } else {
                     // Not inside a scrolling container, so show the feedback right away
                     setPressed(true); //comment by bran
                     checkForLongClick(0);
                 }
                 break;

请注意Bran的代码行,它们是不同的。 setPressed(真);不仅是mPrivateFlags | = PRESSED;和refreshDrawableState(); ,但是dispatchSetPressed。

如果Google中有任何Android SDK开发者,您是否想告诉我为什么要将mPrivateFlags | = PRESSED更改为setPressed(true);。

0 个答案:

没有答案