本文介绍了CoordinatorLayout + TabView + AnimateView(从顶部开始)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我正在玩 CoordinatorLayout TabView

1)我的目标是什么?


  • CoordinatorLayout TabView

  • 当我滚动时当时的一个视图 .GIF 下移

  • TickView 顶部的 Stick (位于AppBar中)。

  • CoordinatorLayout with TabView
  • When I scroll up at that time One View As show in .GIF move down.
  • and Stick on the Top of the TabView (inside AppBar).

2)我到达哪里了?


  • CoordinatorLayout TabView 进行漂亮的滚动。

  • 带有Appbar的TabView,然后在滚动RecyclerView之后停止顶部滚动。

  • CoordinatorLayout with TabView with pretty scrolling.
  • TabView with Appbar Stop Scrolling At Top after Then Scroll RecyclerView.

3)我在哪里停留?


  • 当我向上滚动 一个视图向下滚动但TabView摇杆在顶部不像第一张图片

  • When I scroll Up One View Scroll Down but TabView Stick At Top not like 1st gif.

4)代码段


  • Xml文件

  • Xml file

<android.support.design.widget.AppBarLayout
    android:id="@+id/main.appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <!--- ADD TAB_LAYOUT HERE -->


    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/main.collapsing"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll">

        <ImageView
            android:id="@+id/main.backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@drawable/abc"
            app:layout_collapseMode="none" />


        <!-- ADD ANY THING THAT GETS SCROLLED ALL THE WAY UP WITH TOOLBAR -->
    </android.support.design.widget.CollapsingToolbarLayout>


    <!-- our tablayout to display tabs  -->
    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"

        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="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


Java文件(将上视图向下移动)

Java file (move upper view down code)

AppBarLayout ab = (AppBarLayout) findViewById(R.id.main_appbar);ab.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {

        int ScrollStart = (ab.getHeight() - tabLayout.getHeight() - llTop.getHeight() - llTop.getHeight());
        int scrollStop = (ab.getHeight() - tabLayout.getHeight() - llTop.getHeight());
        if ((-verticalOffset) > ScrollStart && (-verticalOffset) < scrollStop) {
            llTop.setVisibility(View.VISIBLE);
            llTop.setTranslationY(((-verticalOffset) - ScrollStart) - llTop.getHeight());
            Log.e("point", "" + ((-verticalOffset) - ScrollStart));

        } else if ((-verticalOffset) >= scrollStop) {
            llTop.setVisibility(View.VISIBLE);
        } else {
            llTop.setVisibility(View.INVISIBLE);
        }


    }
});


推荐答案

有点棘手。.

只需尝试以这种方式 CollapsingToolbarLayout setMinimumHeight ,并让我

just try to setMinimumHeight of your CollapsingToolbarLayout like this way and do let me know.

CollapsingToolbarLayout layoutCollapsing = (CollapsingToolbarLayout) rootView.findViewById(R.id.layoutCollapsing);
layoutCollapsing.setMinimumHeight(120); 

此处根据您的需要计算最小高度,并将其设置为 setMinimumHeight(120 )值。

here calculate your minimum height as per your need and set it in place of setMinimumHeight(120) value.

这篇关于CoordinatorLayout + TabView + AnimateView(从顶部开始)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 11:48