在我的onCreateView
我有以下代码将自定义视图填充到我的LinearLayout
StageViewer
扩展View
。
layout = (LinearLayout)rootView.findViewById(R.id.lo1);
for (int i = 0 ; i < 6 ; i ++)
{
StageViewer viewer = new StageViewer(i,callingActivity,this, 0, Global.STAGE_VIEW);
layout.addView(viewer);
stageList.add(viewer);
}
在我的应用程序中,用户可以选择将所有视图设置为默认模式
public void resetToDefault()
{
for (int i = 0 ; i < 6 ; i ++)
{
StageViewer viewer = new StageViewer(i,callingActivity,this, 0, Global.STAGE_VIEW);
layout.addView(viewer);
stageList.add(viewer);
}
}
但重置时,新视图不可见(显示空布局)。
我试过
viewer.invalidate();
layout.refreshDrawableState();
我错过了什么吗?
答案 0 :(得分:0)
public void resetToDefault()
{
layout.removeAllViews();
stageList.clear();
for (int i = 0 ; i < 6 ; i ++)
{
StageViewer viewer = new StageViewer(i,callingActivity,this, 0, Global.STAGE_VIEW);
layout.addView(viewer);
stageList.add(viewer);
}
}
答案 1 :(得分:0)
也许缺少布局参数?
LinearLayout.LayoutParams layoutParams =
new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
viewer.setLayoutParams(layoutParams);
layout.addView(viewer);