TransitionDrawable是否不考虑填充?

| 我尝试了此处发布的可接受的解决方案,但它似乎忽略了填充。当第二个视图(在这种情况下为按钮)显示时,它比带有填充的原始视图小得多。有没有解决方法?谢谢     
已邀请:
是的,
TransitionDrawable
LayerDrawable
开始扩展,忽略了填充。这是基本Android代码中的
getPadding()
方法,它摆脱了您指定的任何内容:
    @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;
    }
请在此处查看基本的Android代码。 为了解决这个问题,我必须先保存填充值,然后在视图上设置错误的可绘制背景:
    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);
    

要回复问题请先登录注册