2016-04-02 65 views
1

这是我的布局文件。按钮不显示在活动的底部 - android

<?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/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.CoordinatorLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:id="@+id/coordinatorLayout" 
     android:orientation="vertical"> 

     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

      <include 
       android:id="@+id/toolbar" 
       layout="@layout/toolbar" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       app:layout_scrollFlags="scroll|enterAlways" 
       android:layout_alignParentTop="true"/> 


      <android.support.design.widget.TabLayout 
       android:id="@+id/tab_layout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/toolbar" 
       android:background="@color/primary" 
       android:elevation="6dp" 
       android:minHeight="?attr/actionBarSize" 
       app:tabIndicatorColor="@android:color/white" 
       app:tabIndicatorHeight="4dp" 
       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/> 

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

     <android.support.v4.view.ViewPager 
      android:id="@+id/pager" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/tab_layout" 
      android:layout_above="@+id/floating_button" 
      android:background="@color/windowBackground" 
      android:paddingLeft="30dp" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

     <Button android:id="@+id/floating_button" 
      android:layout_width="match_parent" 
      android:layout_alignParentBottom="true" 
      android:layout_height="wrap_content" 
      android:text="Go to Shopping Cart" 
      android:theme="@style/MyButton"/> 


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

    <fragment 
     android:id="@+id/fragment_navigation_drawer" 
     android:name="com.wokoshop.sony.fragment.FragmentDrawer" 
     android:layout_width="@dimen/nav_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     app:layout="@layout/fragment_navigation_drawer" 
     tools:layout="@layout/fragment_navigation_drawer" /> 

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

我想显示活动的按钮底部。但它根本不显示。

有人可以帮助我我失踪了吗?

+0

看到这一点。 https://guides.codepath.com/android/floating-action-buttons –

回答

3

我认为你有几个小问题导致你的问题。

1)您试图使用cooridnator布局作为相对布局,所以按钮alignParentBottom不会有任何效果。

2)协调器布局的方向是线性布局属性,不起作用。

3)协调器布局或其中的任何内容不使用完整的父对象,它们都只是wrap_parent。

阅读您的布局我想你会想是这样的:

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

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

      <android.support.design.widget.AppBarLayout 
       android:id="@+id/appBarlayout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

       <!-- Whatever views you want here, your tablayout etc--> 

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

      <android.support.v4.view.ViewPager 
       android:layout_below="@+id/appBarlayout" 
       android:layout_above="@+id/button" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

      </android.support.v4.view.ViewPager> 

      <Button 
       android:id="@+id/button" 
       android:text="Hey" 
       android:layout_alignParentBottom="true" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

     </RelativeLayout> 

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