简体   繁体   English

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

[英]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.

相关问题 使用毕加索将图像调整为全宽和固定高度 - Resize image to full width and fixed height with Picasso 在片段android的textview中不显示全文 - not showing full text in textview in a fragment android 如何设置相对布局高度等于其宽度? - How to set relativelayout height equal to its width? 用Java将图像缩小到其高度和宽度的一半 - Shrink an image to half its height and width in java 自定义视图未显示:没有高度,但仍然宽 - Custom View not showing: no height, but still width JTableHeader的工具提示未显示其列的宽度 - Tooltips of JTableHeader is not showing the width of its column 将 ImageView (及其 src)适合布局宽度并使其高度成比例 - Fit a ImageView (and its src) to the layout width and make its height proportional 使用LayoutParam在android Fragment中动态设置图像视图的高度和宽度 - Dynamically setting height and width of a image view in android Fragment using LayoutParam Android / Google Maps API-计算完整地图的宽度和高度(以像素为单位) - Android / Google Maps API - Calculate width and height in pixel of the full Map javaFX 2.0将组件设置为直接父级的全宽和高度 - javaFX 2.0 set component to full width and height of immediate parent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM