Dr.*_*dRO 6 android android-layout swiperefreshlayout android-collapsingtoolbarlayout android-appbarlayout
在我的应用程序中我使用内部CollapsingToolbarLayout跟随.我想要的是检测从中扫过,但是检测到并忽略滑动.这是我的XML:NestedScrollViewSwipeRefreshLayoutSwipeRefreshLayoutCollapsingToolbarLayoutNestedScrollViewCollapsingToolbarLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.support.design.widget.CoordinatorLayout
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="256dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="@dimen/expanded_toolbar_title_margin_start"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/profilePic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/ic_split_big_profile"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<include
android:id="@+id/toolbar_layout"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/transactions_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="500dp">
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="@dimen/fab_margin_bottom"
android:layout_marginRight="@dimen/fab_margin_right"
android:onClick="addTxn"
android:src="@drawable/ic_action_add_transaction_light"
app:elevation="6dp"
app:fabSize="normal" />
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
有人用这种东西吗?
小智 5
如AppBarLayout文档中所述,它必须是CoordinatorLayout的直接子代
此视图在很大程度上取决于在CoordinatorLayout中用作直接子项.如果您在另一个ViewGroup中使用AppBarLayout,其大部分功能将无法正常工作.
因此,我不确定必须包含SwipeToRefreshLayout以与CollapsingToolbar一起使用,因为NestedScrollView也必须是直接子项.
这是另一个响应,有助于附加SwipeRefreshLayout并仅在appBar未拆分时激活它,但它们没有使用NestedScrollView,这对我不起作用:(
编辑我找到了解决我的问题的方法:我使用的ListView必须设置为嵌套滚动,而不是将其放在NestedScrollView中,或者用RecycleView替换:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
listView.setNestedScrollingEnabled(true);
}
Run Code Online (Sandbox Code Playgroud)
因此,您的问题的解决方案应该是将NestedScrollView包装在SwipeRefreshLayout中.
| 归档时间: |
|
| 查看次数: |
3057 次 |
| 最近记录: |