折叠工具栏布局 - 全高图像并在开始时滚动
Collapsing Toolbar Layout - full height Image and scrolled at start
我的布局与此非常相似:http://antonioleiva.com/collapsing-toolbar-layout/ - 折叠工具栏的经典方法。
我想用以下功能扩展它:
ImageView 是全屏高度,在 activity 启动时它会自动向下滚动一半高度。当 activity 开始并且用户向下滚动时,它会以旧方式运行,但是(在 activity 开始时)当他向上滚动时,他可以一直向上滚动以使图像全屏高度大小.
我需要采取哪些步骤才能使它按照我想象的方式运行?
这是总体思路。
Activity:
public void setupMovingBar(final Boolean full) {
final Display dWidth = getWindowManager().getDefaultDisplay();
appBarLayout.post(new Runnable() {
@Override
public void run() {
int heightPx = dWidth.getHeight();
if (!full) {
heightPx = dWidth.getHeight() - (dWidth.getHeight() * 1 / 3);
}
setAppBarOffset(heightPx);
}
});
}
private void setAppBarOffset(int offsetPx) {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
behavior.onNestedPreScroll(clContent, appBarLayout, null, 0, offsetPx, new int[]{0, 0});
}
我的布局与此非常相似:http://antonioleiva.com/collapsing-toolbar-layout/ - 折叠工具栏的经典方法。 我想用以下功能扩展它:
ImageView 是全屏高度,在 activity 启动时它会自动向下滚动一半高度。当 activity 开始并且用户向下滚动时,它会以旧方式运行,但是(在 activity 开始时)当他向上滚动时,他可以一直向上滚动以使图像全屏高度大小.
我需要采取哪些步骤才能使它按照我想象的方式运行?
这是总体思路。 Activity:
public void setupMovingBar(final Boolean full) {
final Display dWidth = getWindowManager().getDefaultDisplay();
appBarLayout.post(new Runnable() {
@Override
public void run() {
int heightPx = dWidth.getHeight();
if (!full) {
heightPx = dWidth.getHeight() - (dWidth.getHeight() * 1 / 3);
}
setAppBarOffset(heightPx);
}
});
}
private void setAppBarOffset(int offsetPx) {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
behavior.onNestedPreScroll(clContent, appBarLayout, null, 0, offsetPx, new int[]{0, 0});
}