0

我正在StateListDrawable为我的一个自定义视图以编程方式创建背景。为了使drawable正常工作,constantSize需要设置为true。创建 时StateListDrawable,这只是一个 XML 属性,但看起来该属性并没有在类中公开。我已经使用以下代码解决了这个问题:

StateListDrawable drawable = new StateListDrawable();
((DrawableContainer.DrawableContainerState) drawable.getConstantState()).setConstantSize(true);

有没有更清洁的方法来做到这一点?

4

0 回答 0