使用CoordinatorLayout + AppBarLayout + CollapsingToolbarLayout可以实现折叠效果
CollapsingToolbarLayout + Toolbar组合使用可以实现header固定在页面顶部,但是有时候希望给CollapsingToolbarLayout设置一个最小高度,使页面最大只能滚动到指定的一个点,但是此时给CollapsingToolbarLayout设置minHeight不生效。分析CollapsingToolbarLayout源码找到了原因,记录一下。
先放自己看源码得到的结论:
CollapsingToolbarLayout代码分析:
ensureToolbar方法:
private void ensureToolbar() {
...
// 1
if (toolbarId != -1) {
// If we have an ID set, try and find it and it's direct parent to us
this.toolbar = findViewById(toolbarId);
if (this.toolbar != null) {
toolbarDirectChild = findDirectChild(this.toolbar);
}
}
// 2
if (this.toolbar == null) {
// If we don't have an ID, or couldn't find a Toolbar with the correct ID, try and find
// one from our direct children
Toolbar toolbar = null;
for (int i = 0, count = getChildCount(); i < count; i++) {
final View child = getChildAt(i);
如对本文有疑问, 点击进行留言回复!!
android studio 55线程更新UI handler
使用枚举 Enum 来减少 if else,快来看看适不适合你吧?
三方app跳转APN设置提示“此用户无权修改接入点名称设置”解决方案
网友评论