Gra*_*eme 7 android android-coordinatorlayout android-appbarlayout
使用CoordinatorLayout和AppBarLayout还有更多问题.
我正在尝试实现在向下滚动时让工具栏滚出屏幕并在向上滚动时返回屏幕的基本功能.
但是,我当前的设置显示一个问题:不仅工具栏没有滚动,ListView似乎在底部渲染屏幕.它几乎就像被AppBarLayout高度所抵消一样.
这是一个描述问题的gif,请注意最终项目也被切断,ScrollBar也在屏幕外:
我的布局很标准:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:background="@color/orange"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeToRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ExpandableListView
android:id="@+id/listView"
android:groupIndicator="@android:color/transparent"
android:layout_width="match_parent"
android:dividerHeight="0px"
android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
CoordinatorLayout仅适用于RecyclerView或NestedScrollView.Try在NestedScrollView中包装您的ExapandableListView或使用以下代码为ExpandableListView创建NestedScrollingEnable.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
expandablelistView.setNestedScrollingEnabled(true);
}else {
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mSwipeLayout.getLayoutParams();
params.bottomMargin = heightOfAppBarCompat;
mSwipeLayout.setLayoutParams(params);
}
Run Code Online (Sandbox Code Playgroud)
编辑您可以使用else语句在21之前按预期进行滚动工作.
| 归档时间: |
|
| 查看次数: |
3130 次 |
| 最近记录: |