安卓:儿童视野共享在果冻豆其父视图按下状态(Android: Child view sharing

2019-07-17 21:17发布

代码注释:1. RelativeLayout的可点击的ATTR设置为true,它有它的可点击的ATTR设置为false子视图。 2.没有任何duplicateParentState ATTR,换句话说,duplicateParentState是假的。 3.孩子的看法是TextView的,其文字颜色为颜色选择,所以它可以检查按下状态。

行为:level16之前,点击RelativeLayout的时候,按下状态不会传染给子女学费视图。 然而,在16级以后,就可以了。

原因:setPressed ------> dispatchSetPressed ------>发射按压状态的儿童观看-----> childView.setPressed

View.java的onTouchEvent在15级,

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;

View.java的onTouchEvent在16级,

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;

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

如果在谷歌任何Android SDK开发者,你想告诉我为什么你改变mPrivateFlags | =按下setPressed(TRUE);.

文章来源: Android: Child view sharing pressed state from its parent view in Jelly Bean