2
我目前有一个非常具体的挑战。 这是事情:自定义属性 - 方向更改
我建立了一个自定义视图,我想从xml布局中设置一个特定的属性。 我在视图的构造函数中获得我的自定义属性。 现在经过方向更改此构造函数是不再调用,但我为自定义属性设置了不同的值。 是否有任何方式自动获得这些新值,或者我必须手动设置方向更改(或再次膨胀)?
自定义视图:
public MyCustomView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.MyCustomView,
0, 0);
try {
mAttr = a.getBoolean(R.styleable.MyCustomView_customAttr, false);
} finally {
a.recycle();
}
}
布局景观
<com.me.MyCustomView
custom:customAttr="false" />
布局画像
<com.me.MyCustomView
custom:customAttr="true" />
感谢您的咨询!
非常感谢!解决了!我认为可能会有重新创建视图或手动设置属性的方法...但似乎没有。 – saberrider