[FIXED] Fragment zeigt nicht seine volle Breite und Höhe

Ausgabe

Ich erstelle ein Schiebemenü in meiner Android-App. Aber zur Laufzeit zeigt keines meiner Fragmente ihre volle Größe, wie von ‘match_parent’ festgelegt.

**Das ist das Bild: **

und das ist mein Code

Layout :

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@android:color/holo_red_light"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/hello_blank_fragment" />
</FrameLayout>

Java-Code:

public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
        switch (menuItem.getItemId()){
            case R.id.nav_place_order:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new PlaceOrderPage1Fragment()).commit();
                break;

            case R.id.nav_profile:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new ProfileFragment()).commit();
                break;

            case R.id.nav_settings:
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
                        new SettingsFragment()).commit();
                break;

            case R.id.sample:
                Toast.makeText(this,"Sample",Toast.LENGTH_SHORT).show();
                break;

        }

Lösung

Überprüfen Sie Ihre onCreateView()Fragmentmethode

Sie sollten die Ansicht so aufblasen:

val root = inflater.inflate(R.layout.list_content,container, false);
return root

und stellen Sie sicher, dass das , zu place_holderdem Sie Ihr Fragment hinzufügen, wenn Sie eine Fragmenttransaktion durchführen, sichtbar ist

fragmentTransaction.replace(R.id.fragment_container, YourFragment())

Stellen Sie im obigen Code sicher, dass fragment_container sichtbar ist und die richtige Höhe und Breite hat


Beantwortet von –
alireza easazade


Antwort geprüft von –
Dawn Plyler (FixError Volunteer)

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like