简体   繁体   中英

Fragment is not showing its full width and Height

I am creating a sliding menu in my android app. But at runtime none of my fragments showing their full size as set by 'match_parent'.

**this is the image : **

在此处输入图片说明

and this is my 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;

        }

check your fragment onCreateView() method

you should inflate view like this :

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

and make sure the place_holder which you adding your fragment to when doing fragment transaction is visible

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

in above code make sure fragment_container is visible and has proper height and width

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM