Android Fragment wird über anderem Fragment plaziert

  • Antworten:13
  • Bentwortet
Flo R.
  • Forum-Beiträge: 61

17.12.2015, 22:14:37 via Website

Guten Abend,

ich habe ein Problem mit einem Fragment in Android Studio.
Immer wenn das Fragment gewechselt wird, wird es über dem anderen Fragment platziert (Siehe Screenshots)

Ich hoffe mir kann jemand helfen ;D

imageimage

KontaktFragment.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageView
            android:layout_width="38dp"
            android:layout_height="38dp"
            android:contentDescription="@string/content_Description"
            android:scaleType="fitCenter"
            android:src="@drawable/kontakt_name" />

        <EditText
            android:id="@+id/kontakt_name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:hint="@string/kontakt_name"
            android:inputType="textPersonName" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:orientation="horizontal" >

        <ImageView
            android:layout_width="38dp"
            android:layout_height="38dp"
            android:contentDescription="@string/content_Description"
            android:scaleType="fitCenter"
            android:src="@drawable/kontakt_mail" />

        <EditText
            android:id="@+id/kontakt_mail"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:hint="@string/kontakt_email"
            android:inputType="textEmailAddress" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:orientation="horizontal" >

        <ImageView
            android:layout_width="38dp"
            android:layout_height="38dp"
            android:contentDescription="@string/content_Description"
            android:scaleType="fitCenter"
            android:src="@drawable/kontakt_message" />

        <EditText
            android:id="@+id/kontakt_message"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:hint="@string/kontakt_message"
            android:inputType="textMultiLine" />
    </LinearLayout>

    <Button
        android:id="@+id/kontakt_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="@string/kontakt_senden"
        android:textColor="@android:color/holo_blue_dark" />
</LinearLayout>

Antworten
Frederik B.
  • Forum-Beiträge: 53

17.12.2015, 22:46:22 via Website

Dein "Fragment" ist nur ein anderes Layout oder seh ich das falsch? :D

Weil dann ist das ganz leicht, du baust ein Framelayout um dein Konstrukt und gibst dem Layout dann eine ID z.B. "container".

Oder du kannst auch ein leeres Layout erstellen. wo du die ID reinpackst.

Dann im Code machst du dir eine Variable "ViewGroup" container.

container = (ViewGroup) findViewByID (R.id.container);

//Dann kannst du diese Methode hier nehmen
private void setLayout(ViewGroup container, int layout){
container.addView(getLayoutInflater().inflate((layout), null));
}

damit wechselst du die Layout und rufst vorher noch
container.removeAllViews(); //auf

Also das sollte klappen. :)
must nur aufpassen wann du auf deine Elemente zugreifst, denn nur wenn das Layout aktiv ist findet die App dann auch die ID's :)

— geändert am 17.12.2015, 22:47:26

Antworten
Flo R.
  • Forum-Beiträge: 61

18.12.2015, 06:37:06 via Website

Nein das ist schon ein richtiges Fragment.

Soll ich die Klasse vom Fragment posten?

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

18.12.2015, 07:18:29 via App

Die Methode wie du die Fragments austausch ist heir interessanter. Wahrschrinlich fügst du das neue Fragment einfach nur an und entfernst das alte nicht o.ä.

LG Pascal //It's not a bug, it's a feature. :) ;)

Antworten
Flo R.
  • Forum-Beiträge: 61

18.12.2015, 11:14:49 via Website

So hier der Code vom FragmentTausch

else if (id == R.id.nav_improve) {

       Improve improve1 = new Improve();
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.content_frame, improve1).commit();

— geändert am 18.12.2015, 17:00:54

Antworten
Flo R.
  • Forum-Beiträge: 61

18.12.2015, 19:02:10 via Website

Eigentlich ist da doch alles korrekt oder?

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

18.12.2015, 19:19:58 via Website

Eigentlich ja, sehr komisch.
Hast du mal verstuch vor dem Replace das alte Fragment zu entferen
z.b. mit FragmentManager#popBackstack()

LG Pascal //It's not a bug, it's a feature. :) ;)

Antworten
Flo R.
  • Forum-Beiträge: 61

18.12.2015, 20:12:08 via Website

Bei dem WebView Fragment geht es auch.
Da wird das Fragment replaced.

WebViewFragment1 bnlfrgmnt = new WebViewFragment1();
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.content_frame, bnlfrgmnt).commit();

Antworten
Flo R.
  • Forum-Beiträge: 61

18.12.2015, 21:17:21 via Website

Irgendjemand eine Idee

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

18.12.2015, 21:26:52 via App

Hallo Flo R.!

Bitte nicht pushen, gib doch der Community ein wenig Zeit!

Wenn sich jemand findet, der eine Antwort zu deiner Frage weiß, dann wird er/sie es bestimmt hier posten, also hab noch ein wenig Geduld... :?

LG Pascal //It's not a bug, it's a feature. :) ;)

Antworten
Flo R.
  • Forum-Beiträge: 61

19.12.2015, 17:15:16 via Website

Brauche dringend Hilfe.

Kennst du jemanden der dass wissen könnte ?

Wenn ja kannst du den Thread verlinken ?

Lg Flo

Antworten
Pascal P.
  • Admin
  • Forum-Beiträge: 11.286

19.12.2015, 17:23:49 via Website

Hallo Flo,
jetzt weisst du wie es einem Programmierer bei einem Problem geht.
Wenn ich sowas habe, suche ich stundenlang und irgendwann habe ich die Lösung, dies kannst du auch tun.

Leider habe ich im Momentan auch keine Ahnung wo das Problem liegen könnte.
Trotz deiner "Not" brauchst du diesen Thread nicht pushen, bitte unterlasse dies in Zukunft!
Danke :)

PS: http://www.andreabaccega.com/blog/2015/08/16/how-to-avoid-fragments-overlapping-due-to-backstack-nightmare-in-android/ ;)

— geändert am 19.12.2015, 17:27:36

LG Pascal //It's not a bug, it's a feature. :) ;)

KlausAndy N.

Antworten
Flo R.
  • Forum-Beiträge: 61

19.12.2015, 23:12:54 via Website

Könnte es damit zusammenhängen, dass das Improve Fragment Layout ein LinearLayout ist ?

Antworten
Flo R.
  • Forum-Beiträge: 61

20.12.2015, 00:03:07 via Website

I habe es hingekriegt :D

Es lag daran, dass ich keine Hintergrundfarbe für das Fragment gesetzt hatte.

— geändert am 20.12.2015, 10:25:58

Antworten