Issue
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;
}
Solution
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
Answered By - alireza easazade
Answer Checked By - Katrina (JavaFixing Volunteer)