【发布时间】:2017-11-13 10:02:06
【问题描述】:
大家早上好!
我的应用程序出现滚动问题。我有一个协调器布局和一个列表视图。当我在列表视图中滚动时,我希望顶部布局折叠。 我搜索并发现如果没有 NestedScrollView 这是不可能的,所以我添加了一个。
问题是当我滚动时,只有协调器布局在滚动。
例如,当我向下滚动时,列表视图会像这样卡住:
我还尝试将我的Listview 的layout_height 设置为match_parent,但这并没有改变任何东西。
这是我的代码:
main.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ActionBarNoShadowLight"
android:fitsSystemWindows="true"
app:elevation="0dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
android:fitsSystemWindows="true">
<ImageView
android:id="@+id/mainImage"
android:layout_width="175dp"
android:layout_height="175dp"
android:layout_marginTop="50dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:scaleType="fitCenter"
app:srcCompat="@drawable/ic_document"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/edit_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/BackgroundWhite"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:clipToPadding="false"
android:scrollbars="none"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ListView
android:id="@+id/lstTask"
android:layout_height="match_parent"
android:layout_width="fill_parent"
android:nestedScrollingEnabled="true"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:divider="@null"
/>
<ImageView
android:id="@+id/empty"
android:layout_height="200dp"
android:layout_width="200dp"
android:layout_marginTop="50dp"
android:scaleType="fitCenter"
android:gravity="center"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
app:srcCompat="@drawable/bg_notasks" />
</FrameLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fabAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_plus" />
</android.support.design.widget.CoordinatorLayout>
非常感谢您未来的帮助, 克莱门特。
【问题讨论】:
标签: android listview xamarin android-coordinatorlayout android-collapsingtoolbarlayout