我添加视图到rootview
以这种方式无法从根视图中删除视图
private RelativeLayout addThisView;
private View rootView;
LayoutInflater inflater = LayoutInflater.from(mContext);
addThisView = (RelativeLayout) inflater.inflate(R.layout.loading_temp_cover, null, false);
if(rootView instanceof FrameLayout){
((FrameLayout)rootView).addView(addThisView);
}
试图从根视图中删除视图
/* remove view from the root view start */
rootView = ((Activity) mContext).getWindow().getDecorView().findViewById(android.R.id.content);
RelativeLayout loadingTempCoverRelative =(RelativeLayout) rootView.findViewById(R.id.loadingTempCoverRelative);
if(loadingTempCoverRelative!=null){
if(rootView instanceof FrameLayout){
((FrameLayout)rootView).removeView(loadingTempCoverRelative);
}
}
/* remove view from the root view end */
,然后当我检查loadingTempCover
是存在(下面的代码)。它仍然存在.. 我调试看看;当到达并完成removeView()
函数时,它不会产生任何效果。我仍然可以在rootview
中看到loadingTempCover
布局。我不明白我在哪里做错了..
rootView = ((Activity)mContext).getWindow().getDecorView().findViewById(android.R.id.content);
RelativeLayout loadingTempCoverRelative =(RelativeLayout) rootView.findViewById(R.id.loadingTempCoverRelative);
if(loadingTempCoverRelative!=null){
loadingTempCoverRelative.setVisibility(loadingTempCoverRelative.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
return;
}
我理解的问题。怎么可能android studio导致这个问题。有趣的..我重建项目和removeView函数正在工作。顺便说一句,我不明白你为什么把我的问题标记为没用?这太有趣了.. – fthopkins