2016-02-23 2 views
42

У меня есть CoordinatorLayout который содержит AppBarLayout и FrameLayout который содержит фрагменты.Fix bottom bar in CoordinatorLayout

Один из этих фрагментов содержит TabLayout сверху, один лоток для листа RecyclerView и на нижней панели «домашняя» панель инструментов.

AppBarLayout конфигурируется с app:layout_scrollFlags="scroll|enterAlways"

Моя проблема заключается в том, что как «Панели инструментов» скрываются при Улитка, AppBarLayout и мой «домашний» на панели инструментов в нижней части. Это текущее поведение

enter image description here

Я хотел бы, чтобы зафиксировать нижнюю «самодельный» на панели инструментов, чтобы сохранить видима, но я не могу добиться.

Это XML макета фрагмента

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    > 
    <android.support.design.widget.TabLayout 
     android:id="@+id/toolbarfilter" 
     android:layout_width="match_parent" 
     android:background="@color/azul_asde" 
     app:tabMode="fixed" 
     app:tabMaxWidth="0dp" 
     android:elevation="4dp" 
     app:tabIndicatorColor="@color/verde_pastel" 
     android:layout_height="wrap_content" 
     /> 

    <android.support.v4.widget.SwipeRefreshLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/swipeContainer" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

    <android.support.v7.widget.RecyclerView 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 
    </android.support.v4.widget.SwipeRefreshLayout> 

     <LinearLayout 
     android:id="@+id/toolbarselection" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:paddingTop="10dp" 
     android:paddingBottom="10dp" 
     android:background="@color/azul_asde" 
     android:elevation="4dp" 
     android:visibility="visible" 
     > 
     <ImageView 
      android:id="@+id/delete" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_delete_white_24dp" 
      android:tint="@color/gris_desactivado" /> 
     <ImageView 
      android:id="@+id/select" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_bookmark_border_white_24dp"/> 

     <ImageView 
      android:id="@+id/send" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_send_white_24dp" 
      android:tint="@color/gris_desactivado" /> 

    </LinearLayout> 

</LinearLayout> 

EDIT1:THIS вопросы, кажется, та же проблема.

+0

Не могли бы вы сделать мне одолжение и показать нам, как вы прячетесь нижняя планка? Я не могу понять это ... (мне не нужен верхний батончик, только внизу) – AndreiBogdan

+1

Hi Hanzo, Вы нашли решение этой проблемы? – Sharath

+0

можете ли вы разместить свой XML-файл, который содержит 'CoordinatorLayout' –

ответ

1

Такое поведение в основном удаляет прокрутки флаг SCROLL из AppBarLayout, при прокрутке содержимого в зависимости зрения (RecyclerView, NestedScrollView) меньше, чем высота зрения, то есть. когда прокрутка не нужна. Он также отменяет смещение прокрутки, которое обычно выполняется AppBarLayout.ScrollingViewBehavior. Хорошо работает при добавлении нижнего колонтитула, т.е. , в режиме прокрутки или в ViewPager, где длина содержимого может быть разной на каждой странице.

https://gist.github.com/MaciejKaras/02bff315f00b87d80467a470424f22c3

Ответил уже в https://stackoverflow.com/a/37293634

1

Чтобы исправить нижней панели, во-первых, вы должны использовать активность, где вкладки присутствуют. В этом упражнении используются разные фрагменты. Добавьте ваш tabLayout в этом activity_main_tab.xml

activity_main_tab.xml

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     xmlns:local="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/co_activity_root_layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true"> 

      <android.support.design.widget.AppBarLayout 
       local:theme="@style/Theme.AppBarOverlay" 
       android:id="@+id/toolbar_layout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true"> 

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

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_below="@+id/toolbar_layout"> 

       <FrameLayout 
        android:id="@+id/fl_fragment_container" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        /> 
      </RelativeLayout> 
     </RelativeLayout> 

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

Для использования просмотра фрагмента

fragment_tab.xml

здесь использовать приложение: layout_scrollFlags = "Спиральные | enterAlways" в панели инструментов для его прокрутки

<?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" 
     android:id="@+id/coordinator" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

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

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

      <android.support.design.widget.TabLayout 
       android:id="@+id/tablayout" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:tabIndicatorColor="@color/white" 
       app:tabIndicatorHeight="@dimen/profile_tablayout_indicator_height" 
       android:background="?attr/colorPrimary" 
       app:tabGravity="fill"/> 

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

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

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

Фрагмент Tabs.java

public class FragmentTabs extends BaseFragment{ 

     private View rootView; 
     private ViewPager viewPager; 
     private TabLayout tabLayout; 
     private Toolbar toolbar; 
     private ViewPagerAdapter viewPagerAdapter; 

     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup viewGroupContainer, Bundle savedInstanceState) { 
      rootViewSearch = inflater.inflate(R.layout.fragment_tab, viewGroupContainer, false); 
      initializeLayout(); 
      setUpActionBar(); 
      setUpFragmentObjects(); 

      return rootView; 
     } 


     private void initializeLayout() { 
      toolbar = (Toolbar) rootView.findViewById(R.id.toolbar); 
      viewPager = (ViewPager) rootView.findViewById(R.id.viewpager); 
      tabLayout = (TabLayout) rootView.findViewById(R.id.tablayout); 
     } 


     private void setUpActionBar() { 
      getApplicationContext().setSupportActionBar(toolbarSearch); 
      ActionBar actionBar = getApplicationContext().getSupportActionBar(); 
      if(actionBar != null){ 
       actionBar.setTitle(Constants.BLANK); 
      } 
     } 


     private void setUpFragmentObjects() { 
      viewPagerAdapter = new ViewPagerAdapter(getApplicationContext(), getChildFragmentManager()); 
      viewPager.setAdapter(searchViewPagerAdapter); 
      tabLayout.setupWithViewPager(viewPager); 
     } 
    } 

ViewPagerAdapter.java

public class ViewPagerAdapter extends FragmentPagerAdapter { 

    public ViewPagerAdapter(Activity activity, FragmentManager fragmentManager) { 
     super(fragmentManager); 
    } 


    @Override 
    public Fragment getItem(int position) { 
     Bundle bundle; 
     switch (position) { 
      case 0: // For Tab 1 
       // use fragment for tab 1 
       return fragment1; 
      case 1: // For Tab 2 
       // use fragment for tab 2 
       return fragment2; 
      case 2: // For Tab 3 
       // use fragment for tab 3 
       return fragment3; 
      default: 
       return null; 
     } 
    } 

    @Override 
    public int getCount() { 
     return 3; // no. of Tabs 
    } 

    @Override 
    public CharSequence getPageTitle(int position) { 
     switch (position) { 
      case 0: // Title For Tab1 
       return "Tab1"; 
      case 1: // Title For Tab2 
       return "Tab2"; 
      case 2: // Title For Tab3 
       return "Tab3"; 
      default: 
       return null; 
     } 
    } 
} 
1

Вы можете попробовать и добавить collapseMode на YOUT панели инструментов что-то вроде этого.

Ваш appBarLayout кажется прекрасным

Я бы посоветовал U посмотреть по этой ссылке: https://github.com/codepath/android_guides/wiki/Handling-Scrolls-with-CoordinatorLayout `

<android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/holo_blue_light" 
     android:fitsSystemWindows="true" 
     app:expandedTitleMarginEnd="64dp" 
     app:expandedTitleMarginStart="48dp" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      app:layout_collapseMode="pin" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways"/> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tablayout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabIndicatorColor="@color/white" 
      app:tabIndicatorHeight="@dimen/profile_tablayout_indicator_height" 
      android:background="?attr/colorPrimary" 
      app:tabGravity="fill"/> 

    </android.support.design.widget.CollapsingToolbarLayout> 
1

я столкнулся с той же проблемой здесь является то, как это работает для меня

Remove AppBarLayoutlayout_behavior поэтому он установлен сверху. Определите FrameLayout layout_behavior как app:layout_behavior="@string/appbar_scrolling_view_behavior", чтобы он отрегулировал FrameLayout ниже AppBarLayout. Таким образом, ваш контент макета рамки будет прокручиваться, но не панель инструментов. CoordinatorLayout макета как следующий

<?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.next_tech.teebox.GridView"> 

    <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" 
      app:titleTextColor="@android:color/white" /> 

    </android.support.design.widget.AppBarLayout> 
<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 


</FrameLayout> 


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

Это XML из вашего макета фрагмента, где ваш recyclerView прокрутки без воздействия на TabLayout и снизу Linear Layout.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    > 
    <android.support.design.widget.TabLayout 
     android:id="@+id/toolbarfilter" 
     android:layout_width="match_parent" 
     android:background="@color/colorPrimary" 
     app:tabMode="fixed" 
     app:tabMaxWidth="0dp" 
     android:elevation="4dp" 
     app:tabIndicatorColor="@color/btnBackground" 
     android:layout_height="?android:actionBarSize" 
     /> 

    <android.support.v4.widget.SwipeRefreshLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/swipeContainer" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 
    </android.support.v4.widget.SwipeRefreshLayout> 

    <LinearLayout 
     android:id="@+id/toolbarselection" 
     android:layout_width="match_parent" 
     android:layout_height="?android:actionBarSize" 
     android:orientation="horizontal" 
     android:background="@color/colorPrimary" 
     android:layout_gravity="bottom" 
     android:elevation="4dp" 
     android:visibility="visible" 
     > 
     <ImageView 
      android:id="@+id/delete" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_gravity="center" 
      app:srcCompat="@android:drawable/ic_menu_delete" /> 
     <ImageView 
      android:id="@+id/select" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="1" 
      app:srcCompat="@drawable/white_arrow" /> 

     <ImageView 
      android:id="@+id/send" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_gravity="center" 
      app:srcCompat="@drawable/ic_send_holo_dark" /> 

    </LinearLayout> 

</LinearLayout> 

Я надеюсь, что это помогает кто-то благодарит

для получения дополнительной информации - Scrolling Behavior for Appbars in Android

1

Вы не можете сделать это в coordinatorlayout. поэтому используйте RelativeLayout и в его конструкции собственного макета

4

Попробуйте этот макет:

<?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:id="@+id/container"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/bottom_navigation" 
     android:layout_alignParentTop="true"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
     <android.support.v7.widget.CardView 
      xmlns:card_view="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/card_view" 
      android:layout_width="match_parent" 
      android:layout_margin="10dp" 
      android:layout_height="110dp" 
      android:padding="15dp" 
      card_view:cardElevation="2dp" 
      card_view:cardCornerRadius="4dp"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="Test" /> 

     </android.support.v7.widget.CardView> 


     <android.support.v7.widget.CardView 
      xmlns:card_view="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/card_view1" 
      android:layout_width="match_parent" 
      android:layout_margin="10dp" 
      android:layout_height="110dp" 
      android:padding="15dp" 
      card_view:cardElevation="2dp" 
      card_view:cardCornerRadius="4dp"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="Test" /> 

     </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/card_view3" 
       android:layout_width="match_parent" 
       android:layout_margin="10dp" 
       android:layout_height="110dp" 
       android:padding="15dp" 
       card_view:cardElevation="2dp" 
       card_view:cardCornerRadius="4dp"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:text="Test" /> 

      </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/card_view4" 
       android:layout_width="match_parent" 
       android:layout_margin="10dp" 
       android:layout_height="110dp" 
       android:padding="15dp" 
       card_view:cardElevation="2dp" 
       card_view:cardCornerRadius="4dp"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:text="Test" /> 

      </android.support.v7.widget.CardView> 

      <android.support.v7.widget.CardView 
       xmlns:card_view="http://schemas.android.com/apk/res-auto" 
       android:id="@+id/card_view5" 
       android:layout_width="match_parent" 
       android:layout_margin="10dp" 
       android:layout_height="110dp" 
       android:padding="15dp" 
       card_view:cardElevation="2dp" 
       card_view:cardCornerRadius="4dp"> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:text="Test" /> 

      </android.support.v7.widget.CardView> 
     </LinearLayout> 
    </ScrollView> 


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="bottom" 
     android:gravity="bottom"> 

     <android.support.design.widget.BottomNavigationView 
      android:layout_width="match_parent" 
      android:layout_height="56dp" 
      android:layout_weight="1" 
      android:foregroundGravity="bottom" 
      android:background="@color/green" 
      app:itemIconTint="@color/white" 
      app:itemTextColor="@color/white" 
      android:id="@+id/bottomnav" 
      app:menu="@menu/main"> 


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

    </RelativeLayout> 



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

попробовать это

<?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:id="@+id/container"> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/bottom_navigation" 
    android:layout_alignParentTop="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 
    <android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/card_view" 
     android:layout_width="match_parent" 
     android:layout_margin="10dp" 
     android:layout_height="110dp" 
     android:padding="15dp" 
     card_view:cardElevation="2dp" 
     card_view:cardCornerRadius="4dp"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="Test" /> 

    </android.support.v7.widget.CardView> 


    <android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/card_view1" 
     android:layout_width="match_parent" 
     android:layout_margin="10dp" 
     android:layout_height="110dp" 
     android:padding="15dp" 
     card_view:cardElevation="2dp" 
     card_view:cardCornerRadius="4dp"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="Test" /> 

    </android.support.v7.widget.CardView> 

     <android.support.v7.widget.CardView 
      xmlns:card_view="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/card_view3" 
      android:layout_width="match_parent" 
      android:layout_margin="10dp" 
      android:layout_height="110dp" 
      android:padding="15dp" 
      card_view:cardElevation="2dp" 
      card_view:cardCornerRadius="4dp"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="Test" /> 

     </android.support.v7.widget.CardView> 

     <android.support.v7.widget.CardView 
      xmlns:card_view="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/card_view4" 
      android:layout_width="match_parent" 
      android:layout_margin="10dp" 
      android:layout_height="110dp" 
      android:padding="15dp" 
      card_view:cardElevation="2dp" 
      card_view:cardCornerRadius="4dp"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="Test" /> 

     </android.support.v7.widget.CardView> 

     <android.support.v7.widget.CardView 
      xmlns:card_view="http://schemas.android.com/apk/res-auto" 
      android:id="@+id/card_view5" 
      android:layout_width="match_parent" 
      android:layout_margin="10dp" 
      android:layout_height="110dp" 
      android:padding="15dp" 
      card_view:cardElevation="2dp" 
      card_view:cardCornerRadius="4dp"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:text="Test" /> 

     </android.support.v7.widget.CardView> 
    </LinearLayout> 
</ScrollView> 


<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="bottom" 
    android:gravity="bottom"> 

    <android.support.design.widget.BottomNavigationView 
     android:layout_width="match_parent" 
     android:layout_height="56dp" 
     android:layout_weight="1" 
     android:foregroundGravity="bottom" 
     android:background="@color/green" 
     app:itemIconTint="@color/white" 
     app:itemTextColor="@color/white" 
     android:id="@+id/bottomnav" 
     app:menu="@menu/main"> 


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

</RelativeLayout> 



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