本文介绍了CoordinatorLayout + TabView + AnimateView(从顶部开始)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
昨天
我正在玩 CoordinatorLayout
和 TabView
1)我的目标是什么?
-
CoordinatorLayout
与TabView
- 当我
滚动时当时的
一个视图
如.GIF
下移
。 - 和
TickView
顶部的Stick
(位于AppBar中)。
CoordinatorLayout
withTabView
- When I
scroll up
at that timeOne View
As show in.GIF
move down
. - and
Stick
on the Top of theTabView
(inside AppBar).
2)我到达哪里了?
-
CoordinatorLayout
与TabView
进行漂亮的滚动。 - 带有Appbar的TabView,然后在滚动RecyclerView之后停止顶部滚动。
CoordinatorLayout
withTabView
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 StickAt Top
not like1st 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(从顶部开始)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!