我有AppBarLayout,其中包含一些视图。最后一个视图没有scrollflags,因此滚动时视图是粘滞的。一切顺利。但是当我改变一些视图的可见性时,最后一个必须粘贴的视图滚出屏幕。通过debaging我注意到当我将appBar可见性的一些子视图更改为Visible时,appBarLayout.getTotalScrollRange()正在改变,但是当我隐藏时他们,这个价值没有改变,它以某种方式影响滚动。有什么建议我能做什么?
<android.support.design.widget.AppBarLayout
android:id="@+id/main_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:fitsSystemWindows="false"
app:elevation="0dp">
<include
layout="@layout/placement_contracts_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways" />
<include
android:id="@+id/placement_header_container"
layout="@layout/placement_header_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways" />
<include
android:id="@+id/contract_layers_container"
layout="@layout/placement_contract_layers_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/placement_header_container"
android:layout_marginTop="-5dp"
app:layout_scrollFlags="scroll|enterAlways" />
<include
android:id="@+id/placement_strategic_doc_header"
layout="@layout/placement_strategic_doc_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/placement_header_container"
android:layout_marginTop="-7dp"
app:layout_scrollFlags="scroll|enterAlways" />
<include
android:id="@+id/placement_strategic_doc_folder_header"
layout="@layout/placement_strategic_doc_folder_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/placement_header_container"
android:layout_marginTop="-7dp"
app:layout_scrollFlags="scroll|enterAlways" />
<include
android:id="@+id/placement_contract_header"
layout="@layout/placement_contract_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/placement_header_container"
android:layout_marginTop="-7dp"
app:layout_scrollFlags="scroll|enterAlways" />
<include
android:id="@+id/layer_terms_container"
layout="@layout/placement_layer_terms_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/placement_header_container"
android:layout_marginTop="-6dp" />
</android.support.design.widget.AppBarLayout>
答案 0 :(得分:0)
我也有这个问题,我通过添加一个解决方法来解决它,删除隐藏的视图上的滚动标记:
private void _setScrollFlagsEnabled(boolean enable) {
if (_spotlightPager == null || _spotlightHeader == null) {
return;
}
AppBarLayout.LayoutParams headerParams = (AppBarLayout.LayoutParams)_spotlightHeader.getLayoutParams();
AppBarLayout.LayoutParams spotlightParams = (AppBarLayout.LayoutParams)_spotlightPager.getLayoutParams();
if (enable) {
headerParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
spotlightParams.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
} else {
headerParams.setScrollFlags(0);
spotlightParams.setScrollFlags(0);
}
}