Reputation: 1518
i add the view to the rootview
in that way
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);
}
trying to remove view from root view
/* 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 */
and then when i check the loadingTempCover
is exist (below codes). it is still exist..
i debugged and see; when reach and complete the removeView()
function it doesn't effect anything. still i can see the loadingTempCover
layout in rootview
. i couldn't understand where am i doing wrong..
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;
}
Upvotes: -1
Views: 1130
Reputation: 5788
Actually Captain here. I had the same problem with animateLayoutChanges
options and need to say, that it's possible to have this issue. Furthermore, somehow there is no issues with Android 10 Q.
But for all other cases, it's not possible to remove view inside parent with animateLayoutChanges
. It's like make sense, because this view required by parent to finish animate. But any delay will not help, View
will stay with parent after delay too.
Upvotes: 0
Reputation: 786
use following code
((ViewGroup) rootView.getParent()).removeView(namebar);
Upvotes: 0
Reputation: 2209
Try to get the parent directly by the view:
rootView = ((Activity) mContext).getWindow().getDecorView().findViewById(android.R.id.content);
RelativeLayout loadingTempCoverRelative =(RelativeLayout) rootView.findViewById(R.id.loadingTempCoverRelative);
ViewGroup parent = loadingTempCoverRelative.getParent();
if(loadingTempCoverRelative!=null){
if(rootView instanceof FrameLayout && parent != null){
parent.removeView(loadingTempCoverRelative);
}
}
You should test the condition if(rootView instanceof FrameLayout)
as well, the issue is maybe here.
Hope it helps.
Upvotes: 0