【发布时间】:2016-01-15 13:39:39
【问题描述】:
我的视图有问题,如下所示:
如您所见,它应该是一个带有不可滚动 ListView 的可滚动视图。
它由 DrawerLayout 组成,里面有 CoordinatorLayout(AppBarLayout 和 FrameLayout 包含我的片段)和 NavigationView。
activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:background="@color/colorBackground"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_vision"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_vision"
app:menu="@menu/activity_vision_drawer" />
app_bar_vision.xml
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorBar"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways|snap"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"/>
现在是主要部分。我的片段布局由 ScrollView 组成,里面有 RelativeLayout,我有两个 ListView,其高度是根据分配的元素以编程方式设置的。
fragment_preferences.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="@layout/content_preferences" />
</ScrollView>
content_preferences.xml
<RelativeLayout 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"
android:layout_gravity="center_horizontal"
tools:context="dron.mkapiczynski.pl.dronvision.fragment.PreferencesFragment"
tools:showIn="@layout/fragment_preferences">>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Preferencje wizualizacji"
android:id="@+id/preferencesTitle"
android:layout_gravity="center" />
<TextView
android:id="@+id/trackedListTitle"
android:text="Drony śledzone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/preferencesTitle"
android:layout_marginTop="20dp"/>
<ListView
android:id="@+id/trackedDroneList"
android:layout_below="@+id/trackedListTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:layout_centerInParent="true"
tools:showIn="@layout/fragment_preferences"/>
<TextView
android:id="@+id/visualizedListTitle"
android:text="Drony do wizualizacji obszaru przeszukanego"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/trackedDroneList"
android:layout_marginTop="20dp"/>
<ListView
android:id="@+id/visualizedDroneList"
android:layout_below="@+id/visualizedListTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_gravity="center_horizontal"
android:layout_centerInParent="true"
android:nestedScrollingEnabled="true"
tools:showIn="@layout/fragment_preferences"/>
通常滚动有效,但只有当我在 ListView 之外的区域触摸屏幕时,例如在我的 TextView 区域。当我尝试使用 ListView 在区域中滚动时,没有任何反应。
如有任何建议,我将不胜感激。我试图实现我自己的 nonScrollingListView 扩展 ListView 认为可以启用父滚动但没有帮助。 我也读过关于使用 LinearLayout 而不是 ListView 但也许还有一种方法可以将 ListView 与 ScrollView 一起使用?
【问题讨论】:
-
当您嵌套可滚动视图时会发生这种情况...系统对要监听的哪个滚动事件感到困惑:
ListView's ?ScrollView的?
标签: android listview scroll scrollview android-relativelayout