Yesterday
我使用CoordinatorLayout
TabView
一起玩
1)我的目标是什么?
CoordinatorLayout
与TabView
scroll up
One View
如 .GIF
move down
中所示。 Stick
位于TabView
的顶部(AppBar内部)。 2)我到达的地方?
CoordinatorLayout
TabView
非常滚动。 3)我卡住的地方?
scroll Up
One View
向下滚动但TabView Stick At Top
不像1st gif
。4)代码段
Xml文件
<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文件(移动上方查看代码)
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);
}
}
});
答案 0 :(得分:7)
这很棘手......
尝试以这种方式 CollapsingToolbarLayout 的 setMinimumHeight 并告诉我。
CollapsingToolbarLayout layoutCollapsing = (CollapsingToolbarLayout) rootView.findViewById(R.id.layoutCollapsing);
layoutCollapsing.setMinimumHeight(120);
根据您的需要计算您的最小身高,并将其设置为 setMinimumHeight(120)值。