[英]Fragment is not showing its full width and Height
I am creating a sliding menu in my android app. 我正在我的android应用程序中创建一个滑动菜单。 But at runtime none of my fragments showing their full size as set by 'match_parent'.
但是在运行时,我的所有片段都没有显示出由“ 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 : Java代码:
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 检查您的片段
onCreateView()
方法
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 并确保在进行片段交易时添加片段的
place_holder
可见
fragmentTransaction.replace(R.id.fragment_container, YourFragment())
in above code make sure fragment_container is visible and has proper height and width 在上面的代码中,请确保fragment_container可见并且具有适当的高度和宽度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.