2017-08-24 2 views
-2

entferne ich auf die rootview auf diese Weise AnsichtKann nicht Ansicht von Stammansicht

/* 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 */ 

von Stammansicht entfernen

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); 
} 

versuchen, die Ansicht hinzufügen und dann, wenn ich das überprüfen loadingTempCover ist existieren (unter Codes). es ist immer noch existent .. ich debuggte und sehe; Wenn die Funktion removeView() erreicht und vervollständigt wird, hat das keinerlei Auswirkungen. immer noch kann ich das loadingTempCover Layout in rootview sehen. Ich konnte nicht verstehen, wo mache ich falsch ..

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; 
} 
+0

i das Problem verstanden. Wie kann es möglich sein, dass Android Studio dieses Problem verursacht. interessant .. Ich baue das Projekt neu und removeView funktioniert jetzt. Übrigens, ich verstehe nicht, warum Sie meine Frage als nicht nützlich markieren? das ist auch so interessant. – fthopkins

Antwort

0

Versuchen Sie, die Eltern direkt von der Ansicht erhalten:

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); 
    } 
} 

Sie den Zustand if(rootView instanceof FrameLayout) auch prüfen sollte, ist die Frage vielleicht hier .

Ich hoffe, es hilft.

+0

danke für die antwort. Es ist nicht relevant mit ob Bedingung oder getParent. Android Studio verursacht dieses Problem. Ich baue das Projekt neu und das Problem ist jetzt weg. – fthopkins

0

Verwendung folgender Code

((ViewGroup) rootView.getParent()).removeView(namebar); 
Verwandte Themen