【发布时间】:2017-01-03 16:07:31
【问题描述】:
下面的 ListView 不滚动。它使用第一个布局中的 ViewPager 组件。 ViewPager 的片段是动态引入的。 ListView 的 onScroll 事件适用于加载 100 个项目,但滚动不起作用。 有人能看到吗
我有以下 xml 布局:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@color/background_primary"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/abl_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/text_header_field"
app:theme="@style/MyMaterialTheme"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/text_header_field"
app:layout_scrollFlags="scroll|enterAlways"
android:padding="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:popupTheme="@style/CDTheme.NoActionBar.PopupOverlay"
>
<com.cashdash.views.components.TypefaceTextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:customTypeface="fonts/Montserrat-Light.otf"
android:layout_gravity="center"
android:textSize="16sp"
android:text="@string/title_activity_transaction"
android:gravity="center"
android:textColor="@color/text_title"
android:textAllCaps="true"
android:background="@color/text_header_field"
/>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabIndicatorColor="@color/background_primary_to"
app:tabBackground="@color/text_header_field"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabSelectedTextColor="@color/field_value_dark"
app:tabTextColor="@color/tab_inactive"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
这是片段:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TransactionHistoryFragment"
android:background="@color/background_primary">
<ListView
android:id="@+id/lv_transaction"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
/>
</FrameLayout>
更新:
我已经尝试了几件事,这些“合并”解决了这个问题。 一般是嵌套滚动的问题,但解决方法是:
- 从父层次结构中拦截Touch事件并实现滚动
- 为 API 21+ 使用 xml 属性 android:nestedScrollingEnabled="true"
- 在 ViewPager 上使用页面转换作为可选解决方案
每一个都是解决方案的一个组成部分。
【问题讨论】:
-
很可能是 Z-Index 问题,一个视图(可能是
ViewPager)阻止了您的ListView的触摸事件。 -
是的,它与其他可滚动组件有关。我试过使用nestedScrollingEnabled="true",但没有用。
-
我会将嵌套的
ListView移出任何其他组件并单独测试它。将它放在 XML 的顶部(首先绘制)以及最后(未嵌套,最后绘制)以进行一些功能测试。如果你得到一些东西,你就知道它是嵌套的。
标签: listview android-fragments android-viewpager android-coordinatorlayout