TransitionDrawable does not account for padding?

I tried the decision posted here , but it seems to ignore the add-on. When the second view is displayed (in this case, the button), it is much smaller than the original, which is indented. Is there a workaround for this? Thanks

+2
source share
1 answer

Yes, it TransitionDrawablecontinues from LayerDrawable, which ignores the addition. This is a method getPadding()in the Android base code that gets rid of everything you specified:

    @Override
    public boolean getPadding(Rect padding) {
        // Arbitrarily get the padding from the first image.
        // Technically we should maybe do something more intelligent,
        // like take the max padding of all the images.
        padding.left = 0;
        padding.top = 0;
        padding.right = 0;
        padding.bottom = 0;
        final ChildDrawable[] array = mLayerState.mChildren;
        final int N = mLayerState.mNum;
        for (int i=0; i<N; i++) {
            reapplyPadding(i, array[i]);
            padding.left += mPaddingL[i];
            padding.top += mPaddingT[i];
            padding.right += mPaddingR[i];
            padding.bottom += mPaddingB[i];
        }
        return true;
    }

See the base Android code here .

, :

    int bottom = theView.getPaddingBottom();
    int top = theView.getPaddingTop();
    int right = theView.getPaddingRight();
    int left = theView.getPaddingLeft();
    theView.setBackgroundResource(R.drawable.faulty_drawable);
    theView.setPadding(left, top, right, bottom);
+7

All Articles