2017-04-06 72 views
0

我有一個奇怪的問題,我BottomNavigationBar的Android - BottomNavigationMenu和ListView的線性佈局

的情況是這樣的: 我有一個包含 活動 - 用於顯示債權債務一點點片段和它的作品 - 用我所有的支出列表視圖和它的作品以及 - 一個bottomNavigationMenuBar的工作部分,實際上它是不是掛靠在我活動的底部,但如果入住的ListView直到ListView控件的底部佔據所有顯示上的空間

我附上一些屏幕來更好的解釋 no good behaviour, it must stay at the bottom 沒有好的行爲,它必須留在底部
enter image description here 的ListView比屏幕更大,它的作品好

這裏是我的XML

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/tab_bck" 
    xmlns:design="http://schemas.android.com/apk/res-auto"> 
     <LinearLayout 
      android:id="@+id/LinearVerticalLayout" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:background="@color/tab_bck" > 

      <android.support.v7.widget.Toolbar 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" 
       android:id="@+id/expenseToolbar" 
       android:layout_height="?attr/actionBarSize" 
       android:elevation="6dp" 
       app:layout_collapseMode="pin" 
       app:layout_scrollFlags="scroll|enterAlways" 
       app:popupTheme="@style/AppTheme" 
       app:navigationIcon="?attr/homeAsUpIndicator" 
       app:titleTextColor="@android:color/white" 
       app:subtitleTextColor="@android:color/white" 
       android:background="@color/colorPrimary"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       /></android.support.v7.widget.Toolbar> 


      <FrameLayout 
       android:id="@+id/fragment" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:name="it.polito.mad17.viral.sliceapp.Fragment_of_money" 
       /> 
      <ListView 
       android:id="@+id/listView2" 
       android:layout_width="match_parent" 
       android:layout_weight="1" 
       android:layout_height="0dp" 
       android:background="@color/tab_bck" 
       android:longClickable="true" 
       /> 

      <android.support.design.widget.BottomNavigationView 

       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/bottom_nav_bar" 
       android:layout_gravity="bottom" 
       design:menu="@menu/bottom_nav_bar_menu" 
       design:itemIconTint="#16a085" 
       design:itemTextColor="#16a085"/> 

     </LinearLayout> 
</android.support.design.widget.CoordinatorLayout> 
+0

使用的RelativeLayout代替的LinearLayout – Sach

回答

0

將您的BottomBar放在線性佈局之外。就像這樣:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/tab_bck" 
    xmlns:design="http://schemas.android.com/apk/res-auto"> 
     <LinearLayout 
      android:id="@+id/LinearVerticalLayout" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:background="@color/tab_bck" > 

      <android.support.v7.widget.Toolbar 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" 
       android:id="@+id/expenseToolbar" 
       android:layout_height="?attr/actionBarSize" 
       android:elevation="6dp" 
       app:layout_collapseMode="pin" 
       app:layout_scrollFlags="scroll|enterAlways" 
       app:popupTheme="@style/AppTheme" 
       app:navigationIcon="?attr/homeAsUpIndicator" 
       app:titleTextColor="@android:color/white" 
       app:subtitleTextColor="@android:color/white" 
       android:background="@color/colorPrimary"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       /></android.support.v7.widget.Toolbar> 


      <FrameLayout 
       android:id="@+id/fragment" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:name="it.polito.mad17.viral.sliceapp.Fragment_of_money" 
       /> 
      <ListView 
       android:id="@+id/listView2" 
       android:layout_width="match_parent" 
       android:layout_weight="1" 
       android:layout_height="0dp" 
       android:background="@color/tab_bck" 
       android:longClickable="true" 
       /> 
</LinearLayout> 
      <android.support.design.widget.BottomNavigationView 

       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/bottom_nav_bar" 
       android:layout_gravity="bottom" 
       design:menu="@menu/bottom_nav_bar_menu" 
       design:itemIconTint="#16a085" 
       design:itemTextColor="#16a085"/> 


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

這應該爲你工作

+0

它工作在我身邊。檢查然後讓我知道它的工作或沒有@ Kalos92 –

+0

作品部分,但問題是:當ListView控件被occpuying所有的最後一個可見項目開始下BottomNavigationBar – Kalos92

+0

屏幕使底部欄高度修正像'60dp'。然後在Linear layout標籤中添加頁邊距'60dp'。就像這樣:'機器人:layout_marginBottom =「60dp' –

0

先給LinearVerticalLayout的android:layout_height = 「match_parent」,可能會起作用

+0

沒有,我在活動中的所有項目消失 – Kalos92