2016-08-22 22 views
0

我刚开始使用片段,但我有问题才能正确使用它们。片段不匹配

这是我的情况。我使用这个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> 

任何人都可以告诉我我错在哪里吗?

在此先感谢。

编辑

存款准备金率的解决方案仅适用于默认选择的项目,第一个片段。如果我更改BottomBar中的项目,第二张牌的布局与我发布的图片相同。任何其他想法?

+0

你介意张贴代码保存用于该片段的占位符的活动? – Chordin4tion

+0

请勿像这样嵌套'DrawerLayout'。把两个抽屉放在一个。 'DrawerLayout'可以带两个抽屉,每边一个。 –

+0

@MikeM。这可能是一个旧约,但你可以在私人信息中解释我吗?我真的很感兴趣 – Jigen

回答

3

使用android:fillViewport=trueScrollViewCoordinatorLayout

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

fillViewPort定义滚动视图是否应该舒展其内容 以填充视口。

source

+0

使用这种方式只有第一个片段使用所有空格,如果我选择另一个项目,在底部酒吧cardview仍然具有相同的高度,像在图片我张贴 – Jigen

+0

是否有另一种解决方案? – Jigen