繁体   English   中英

片段未显示其完整宽度和高度

[英]Fragment is not showing its full width and Height

我正在我的android应用程序中创建一个滑动菜单。 但是在运行时,我的所有片段都没有显示出由“ match_parent”设置的完整大小。

**这是图像:**

在此处输入图片说明

这是我的代码

版面:

<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代码:

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;

        }

检查您的片段onCreateView()方法

您应该像这样膨胀视图:

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

并确保在进行片段交易时添加片段的place_holder可见

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

在上面的代码中,请确保fragment_container可见并且具有适当的高度和宽度

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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