2016-06-14 96 views
0

我想有2工具栏,一个在顶部,并在屏幕底部的另一个。目前最低点仍在顶部显示。我如何解决它?工具栏出现在顶部而不是底部

activity_main.xml中

  <?xml version="1.0" encoding="utf-8"?> 
     <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" 
tools:context="com.example.x.fresh.MainActivity"> 

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

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

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

<include layout="@layout/content_main" /> 

<include 
    layout="@layout/toolbar_bottom" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true"/> 

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

toolbar_bottom.xml

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/toolbar2" 
android:minHeight="?attr/actionBarSize" 
android:background="@color/primary" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

+0

您可以包括''里面content_main toolbar_bottom' '? –

+0

这仍然是一样的效果。 – purplewind

回答

0

如果你不使用的RelativeLayout然后android:layout_alignParentBottom="true"已经没有意义了。

使用此

<?xml version="1.0" encoding="utf-8"?> 
     <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" 
tools:context="com.example.x.fresh.MainActivity"> 

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

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

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

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



<include layout="@layout/content_main" 
      android:layout_below="@+id/appbar" 
      android:id="@+id/content"/> 

<include 
    layout="@layout/toolbar_bottom" 
    android:layout_below="@+id/content" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true"/> 

</RelativeLayout> 

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

appbar是什么? purplewind

+0

@purplewind appbar是'android.support.design.widget.AppBarLayout' –

+0

做u意味着顶部的工具栏的ID?它已被宣布为 purplewind

0

喜请下面的例子

<?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:fitsSystemWindows="true"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:background="?attr/colorPrimary"/> 

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


     <include 
      layout="@layout/test"/> 

     <include 
      android:id="@+id/bottombar" 
      layout="@layout/custom_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true"/> 
    </RelativeLayout> 
</android.support.design.widget.CoordinatorLayout> 

只需添加相对布局

您可以查看拍摄画面enter image description here

+0

是的,我已经做了,如上面我的代码示例所示。我在标签添加 – purplewind

+0

喜请看看我的例子这一点,只是里面cordinatorLayout添加相对布局,或者你可以改用相对布局或@roman_empire Hi.You已经添加了两个答案,请删除其中的一种或将它们合并Cordinator布局 – Sach

+0

。谢谢 –

相关问题