片段不匹配_parent

时间:2016-08-22 07:10:33

标签: android xml android-fragments

我刚刚开始使用片段,但我有正确使用它们的问题。

这是我的情况。当用户点击项目片段发生变化时,我将BottomBar与一些项目一起使用。没关系,但是我无法在第二张卡片的高度设置match_parent。我想使用剩下的所有空间。 这是结果:

Image1

这是我的CDetails.java中的代码,我使用BottomBar和FragmentManager:

 // BottomBar
            mBottomBar = BottomBar.attach(CustomersDetails.this, savedInstanceState);
            //mBottomBar.hideShadow();
            mBottomBar.noNavBarGoodness();
            mBottomBar.noResizeGoodness();
            //mBottomBar.noScalingGoodness();
            mBottomBar.noTabletGoodness();
            //mBottomBar.useFixedMode();
            mBottomBar.setItems(R.menu.bottom_navigation_customers);
            mBottomBar.setOnMenuTabClickListener(new OnMenuTabClickListener() {
                @Override
                public void onMenuTabSelected(@IdRes int menuItemId) {
                    if (menuItemId == R.id.bottomBarCustomerNotes) {

                        FragmentManager fragmentManager = getFragmentManager();
                        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                        CustomersFragmentsNotes notes = new CustomersFragmentsNotes();
                        fragmentTransaction.replace(R.id.fragment_container, notes);
                        fragmentTransaction.commit();

                    }
                    if (menuItemId == R.id.bottomBarCustomerTickets) {

                        FragmentManager fragmentManager = getFragmentManager();
                        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                        CustomersFragmentsTickets tcks = new CustomersFragmentsTickets();
                        fragmentTransaction.replace(R.id.fragment_container, tcks);
                        fragmentTransaction.commit();

                    }
                    if (menuItemId == R.id.bottomBarCustomerContracts) {

                        FragmentManager fragmentManager = getFragmentManager();
                        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                        CustomersFragmentContracts cntrs = new CustomersFragmentContracts();
                        fragmentTransaction.replace(R.id.fragment_container, cntrs);
                        fragmentTransaction.commit();

                    }
                    if (menuItemId == R.id.bottomBarCustomerContacts) {

                        FragmentManager fragmentManager = getFragmentManager();
                        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                        CustomersFragmentContacts cnts = new CustomersFragmentContacts();;
                        fragmentTransaction.replace(R.id.fragment_container, cnts);
                        fragmentTransaction.commit();

                    }
                }

                @Override
                public void onMenuTabReSelected(@IdRes int menuItemId) {

                }
            });

            //Setting colors
            mBottomBar.mapColorForTab(0, "#F44336");
            mBottomBar.mapColorForTab(1, "#7E57C2");
            mBottomBar.mapColorForTab(2, "#5C6BC0");
            mBottomBar.mapColorForTab(3, "#42A5F5");

这是我的activity_cdetails.xml(容器):

    <?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/left_drawer_activity_cdetails"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/right_drawer_activity_cdetails"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/sfondo_sfumato"
        >

        <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            >

            <android.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/AppTheme.AppBarOverlay"
                android:id="@+id/appbar_activity_cdetails">

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar_activity_cdetails"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="?attr/colorPrimary"
                    app:popupTheme="@style/AppTheme.PopupOverlay" />

            </android.support.design.widget.AppBarLayout>


            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:layout_marginTop="55dp"
                >

                <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:card_view="http://schemas.android.com/apk/res-auto"
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:layout_marginBottom="10dp"
                    android:layout_marginStart="10dp"
                    android:layout_marginEnd="10dp"
                    card_view:cardCornerRadius="5dp"
                    card_view:cardBackgroundColor="#FFFFFF"
                    card_view:cardElevation="7dp"
                    >

                    <!--<ScrollView-->
                        <!--android:layout_width="match_parent"-->
                        <!--android:layout_height="match_parent">-->

                    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_margin="5dp"
                        android:weightSum="1"
                        android:orientation="vertical"
                        >

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:id="@+id/title_cdetails"
                            android:layout_marginTop="5dp"
                            android:layout_marginBottom="5dp"
                            android:text="Title"
                            android:textSize="22sp"
                            android:typeface="serif"
                            android:layout_centerHorizontal="true"
                            android:layout_gravity="center"
                            />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="New Text"
                            android:layout_marginBottom="5dp"
                            android:layout_marginLeft="5dp"
                            android:textSize="18sp"
                            android:layout_below="@id/title_cdetails"
                            android:id="@+id/cdetails_nome"
                            />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="5dp"
                            android:layout_marginLeft="5dp"
                            android:layout_below="@id/cdetails_nome"
                            android:text="New Text"
                            android:textSize="18sp"
                            android:id="@+id/cdetails_città"
                            />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="New Text"
                            android:layout_marginBottom="5dp"
                            android:layout_marginLeft="5dp"
                            android:layout_below="@id/cdetails_città"
                            android:textSize="18sp"
                            android:id="@+id/cdetails_indirizzo"
                            />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="New Text"
                            android:layout_below="@id/cdetails_indirizzo"
                            android:layout_marginBottom="5dp"
                            android:layout_marginLeft="5dp"
                            android:textSize="18sp"
                            android:id="@+id/cdetails_provincia"
                            />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="New Text"
                            android:layout_below="@id/cdetails_provincia"
                            android:layout_marginBottom="5dp"
                            android:layout_marginLeft="5dp"
                            android:textSize="18sp"
                            android:id="@+id/cdetails_phone"
                            android:autoLink="phone"
                            />

                    </RelativeLayout>

                    <!--</ScrollView>-->

                </android.support.v7.widget.CardView>

                <!-- Fragment Container -->
                <LinearLayout
                    android:id="@+id/fragment_container"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    >

                </LinearLayout>

            </LinearLayout>

            </ScrollView>


        </android.support.design.widget.CoordinatorLayout>

        <android.support.design.widget.NavigationView
            android:id="@+id/nav_view_right_activity_cdetails"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="end"
            android:fitsSystemWindows="true"
            app:headerLayout="@layout/nav_header_right_c"
            app:menu="@menu/menu_right_c" />

    </android.support.v4.widget.DrawerLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view_left_activity_cdetails"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/menu_left_drawer" />

</android.support.v4.widget.DrawerLayout>

这是activity_c_fragment_notes.xml(第一个片段):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="10dp"
        android:layout_marginStart="10dp"
        android:layout_marginEnd="10dp"
        card_view:cardCornerRadius="5dp"
        card_view:cardBackgroundColor="#B2EBF2"
        card_view:cardElevation="7dp"
        >

        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:text="This is Notes"
        />

    </android.support.v7.widget.CardView>

</LinearLayout>

有谁能告诉我哪里错了?

提前致谢。

修改

RRR解决方案仅适用于默认选定项目,即第一个片段。如果我在BottomBar第二张卡中更改项目的布局与我发布的图片相同。还有其他想法吗?

1 个答案:

答案 0 :(得分:3)

android:fillViewport=true

ScrollView使用CoordinatorLayout
<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">
  

fillViewPort定义scrollview是否应该拉伸其内容   填充视口。

source