onCreateDrawableState永远不会调用 [英] onCreateDrawableState never call
本文介绍了onCreateDrawableState永远不会调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我塔伊新的国家加入到RelativeLayout的,但onCreateDrawableState方法永远不会调用。
I have tye to add new state to RelativeLayout but onCreateDrawableState method is never call.
我的类是:
public class UnreadableRelativeLayout extends RelativeLayout
{
private static final int[] STATE_UNREADED = {R.attr.state_unreaded};
private boolean isUnreaded = false;
public UnreadableRelativeLayout(Context context)
{
super(context);
}
public UnreadableRelativeLayout(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public UnreadableRelativeLayout(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
public void setUnreaded(boolean isUnreaded)
{
if (this.isUnreaded != isUnreaded)
{
this.isUnreaded = isUnreaded;
refreshDrawableState();
}
}
@Override
protected int[] onCreateDrawableState(int extraSpace)
{
final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
if (isUnreaded) mergeDrawableStates(drawableState, STATE_UNREADED);
return drawableState;
}
}
为什么onCreateDrawableState方法从不打电话?
Why onCreateDrawableState method never call?
推荐答案
尝试创建分离的布局安卓duplicateParentState =真正的
,并在你的类它充气。它为我在Android 4.0.4:
Try to create separate layout with android:duplicateParentState="true"
and inflate it in your class. It works for me on Android 4.0.4:
unreadable_relative_layout.xml:
unreadable_relative_layout.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:duplicateParentState="true" >
...
</RelativeLayout>
UnreadableRelativeLayout.java:
UnreadableRelativeLayout.java:
public class UnreadableRelativeLayout extends RelativeLayout {
public UnreadableRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater factory = LayoutInflater.from(context);
factory.inflate(R.layout.unreadable_relative_layout, this);
}
}
这篇关于onCreateDrawableState永远不会调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文