2016-01-24 70 views
1

我想添加页脚到CoordinatorLayout,其中包含TabView + ViewPager将Footer添加到CoordinatorLayout

下面是main.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/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <android.support.design.widget.CoordinatorLayout 
     android:id="@+id/main_content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     tools:context="com.entree.entree.activity.StoreActivity"> 

     <android.support.design.widget.AppBarLayout 
      android:id="@+id/appbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingTop="@dimen/appbar_padding_top" 
      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="@android:color/black" 
       app:layout_scrollFlags="scroll|enterAlways" 
       app:popupTheme="@style/AppTheme.PopupOverlay"> 
       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/ic_action_tray" 
        android:layout_gravity="right" 
        android:layout_marginRight="15dp" 
        android:scaleType="centerInside"/> 

       <ImageView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:src="@drawable/ic_action_find" 
        android:layout_gravity="right" 
        android:scaleType="centerInside" 
        android:layout_marginRight="10dp" 
        /> 
      </android.support.v7.widget.Toolbar> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:background="@android:color/white" 
       app:tabIndicatorColor="#00000000" 
       style="@style/MyCustomTabLayout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

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

      <android.support.v4.view.ViewPager 
       android:id="@+id/container" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       app:layout_behavior="@string/appbar_scrolling_view_behavior" 
       android:layout_above="@+id/llTray" /> 


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

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:visibility="gone" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_search" 
     app:menu="@menu/activity_search_drawer" /> 
</android.support.v4.widget.DrawerLayout> 

这里是XML内容:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_below="@+id/container" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.entree.entree.activity.StoreActivity$PlaceholderFragment"> 


<GridView 
    android:id="@+id/gridView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:numColumns="1" 
    android:stretchMode="columnWidth"> 

</GridView> 

<LinearLayout 
    android:id="@+id/llTray" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="3" 
    android:visibility="gone" 
    android:gravity="center_vertical" 
    android:layout_centerVertical="true" 
    android:background="@color/divider" 
    android:layout_alignParentBottom="true"> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_weight="1" 
     android:layout_gravity="left" 
     android:gravity="left" 
     android:layout_height="wrap_content"> 

     <ImageButton 
      android:id="@+id/btnTray" 
      android:src="@drawable/ic_action_tray_menu" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </RelativeLayout> 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="20sp" 
     android:textStyle="bold" 
     android:layout_gravity="center_horizontal|center_vertical" 
     android:gravity="center_horizontal|center_vertical" 
     android:layout_weight="1" 
     android:text="@string/view_tray" /> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_weight="1" 
     android:gravity="right" 
     android:layout_marginRight="10dp" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:id="@+id/tvTotalPrice" 
      android:layout_width="wrap_content" 
      android:textSize="20sp" 
      android:textStyle="bold" 
      android:text="@string/Rs" 
      android:layout_height="wrap_content" /> 
    </RelativeLayout> 
</LinearLayout> 

页脚是XML格式的内容。

如果我删除:

app:layout_behavior="@string/appbar_scrolling_view_behavior" 

在对主XML View Pager,出现页脚,否则它不会显示。

我怎样才能看到页脚?

+0

请检查此博客 - http://www.javacodegeeks.com/2013/10/android-fixed-header-and-footer-with-scrollable-content-layout-example.html 希望这会帮助你! –

+0

@AdarshYadav没有这个在协调器布局中不起作用 –

+0

您是否想要一直显示页脚?或只是在viewpager? – Mohsen

回答

1

您已经有了:

<GridView 
     android:id="@+id/gridView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:numColumns="1" 
     android:stretchMode="columnWidth" /> 

随着match_parent两个heightwidth它似乎并不好。另外,也许你需要显示ViewPagerNestedScrollView滚动内容将来(需要一个技巧,但你可以做到这一点)。

所以,我的建议是,你应该能够表明页脚在低于ViewPager所有的时间,加入这样的:

<android.support.v4.view.ViewPager 
      android:id="@+id/container" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      android:layout_above="@+id/llTray" /> 

     <!-- Footer aligned to bottom --> 
     <RelativeLayout 
      android:id="@+id/footer" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:background="#FC0" 
      android:gravity="center" 
      app:layout_anchor="@id/main_content" 
      app:layout_anchorGravity="bottom"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="Fixed Footer" 
       android:textColor="#000" 
       android:textSize="20sp" /> 

     </RelativeLayout> 

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

这应该显示页脚所有的时间(即使ViewPager正在崩溃)。


或者,如果你想显示在你的ViewPager

,你应该在你的内容补充一点:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

这意味着,它会把AppbarLayout下面的内容

不管怎么说,你的内容问题来自于GridView就像我说的那样l匹配所有内容,并且您没有ScrollView甚至NestedScrollView以显示其他内容。

+0

Thanx @ LinX64它的工作...我还是不明白的是使用appbar_scrolling_view_behavior。你可以简单地告诉我 –

+0

它用于在AppbarLayout下面放置一个视图。你可以欣赏一下:https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout和https: //developer.android.com/reference/android/support/design/widget/CoordinatorLayout.Behavior.html – Mohsen