TransitionDrawable不占填充? [英] TransitionDrawable doesn't account for padding?

查看:110
本文介绍了TransitionDrawable不占填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过贴接受的解决方案<一href=\"http://stackoverflow.com/questions/2614545/animate-change-of-view-background-color-in-android\">here,但它似乎忽略填充。当第二视图(在这种情况下,一个按钮)显示,它比具有填充原始小得多。是否有一个解决方法吗?谢谢

I tried the accepted solution posted here, but it appears to ignore padding. When the second view (in this case a button) displays, it's much smaller than the original which has padding. Is there a workaround for that? Thanks

推荐答案

TransitionDrawable LayerDrawable 扩展其忽略填充。这是在Android的基础code,你指定哪个摆脱任何事物的 getPadding()方法:

Yes, TransitionDrawable extends from LayerDrawable which ignores the padding. This is the getPadding() method in the base Android code, which gets rid of anything 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;
    }

请参阅base Android的code这里

要对付它,我只好上设置我的看法故障绘制背景前先保存填充值:

To deal with it, I had to first save the padding values before setting the faulty drawable background on my view:

    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);

这篇关于TransitionDrawable不占填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆