gpt4 book ai didi

android - TransitionDrawable 不考虑填充?

转载 作者:太空狗 更新时间:2023-10-29 16:09:35 27 4
gpt4 key购买 nike

我尝试了已接受的解决方案 here ,但它似乎忽略了填充。当第二个 View (在本例中为按钮)显示时,它比具有填充的原始 View 小得多。有解决方法吗?谢谢

最佳答案

是的,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;
}

参见 base Android code here .

为了处理它,我必须先保存填充值,然后再在我的 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);

关于android - TransitionDrawable 不考虑填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6104677/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com