【发布时间】:2013-09-11 15:41:56
【问题描述】:
我有一个使用 FragmentStatePagerAdapter 填充的 viewPager。它工作正常,可以水平浏览填充的页面。
然而viewPager上每个页面的中间部分是由一个listView组成的。这个列表视图有时不适合指定区域,我需要能够垂直滑动。但我目前无法在 viewPager 的这一部分垂直滚动。
看起来 viewPager 正在消耗所有滚动事件(水平和垂直)。
我不想要垂直 viewPager;我在 StackOverflow 上看到了一些答案。
我只希望viewPager中间的section垂直滚动,而这个section是listView
这是带有 viewPager 的选项卡的主布局:
<LinearLayout
android:id="@+id/history"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/fdi_gray">
<android.support.v4.view.ViewPager
android:id="@+id/historyFragment_container"
android:layout_weight="0.85"
android:layout_width="fill_parent"
android:layout_height="0dip"/>
<include layout="@layout/page_indicator_history"
android:layout_height="0dip"
android:layout_width="fill_parent"
android:layout_weight="0.05"
android:background="@color/darker_gray"
android:layout_marginTop="2dp"/>
</LinearLayout>
ViewPager 适配器用来填充上面 viewPager 的布局是这样的:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/spaceHolderLocations">
<TextView
android:id="@+id/locationName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:textStyle="bold"
android:textSize="17sp"/>
<TextView
android:id="@+id/latlon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="@+id/locationName"
android:layout_marginTop="2dp"
android:layout_marginBottom="3dp"
android:layout_centerHorizontal="true"/>
<View
android:id="@+id/listViewStart"
android:layout_width="match_parent"
android:layout_height="0.5dip"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_below="@+id/latlon"
android:background="@color/white" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/fdi_gray"
android:layout_below="@+id/listViewStart"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:divider="@color/white"
android:dividerHeight="0.5dip"
android:padding="1dp">
</ListView>
<View
android:id="@+id/listViewEnd"
android:layout_width="match_parent"
android:layout_height="0.5dip"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_below="@android:id/list"
android:background="@color/white" />
<TextView
android:id="@+id/curingLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/listViewEnd"
android:gravity="center"
android:text="@string/curingLabel"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:textSize="17sp"/>
<TextView
android:id="@+id/curingValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/curingLabel"
android:layout_marginLeft="30dp"
android:layout_alignBottom="@+id/curingLabel"
android:textStyle="bold"
android:textSize="17sp"/>
请注意上述布局中的列表视图。
这是我希望能够滚动的 ViewPager 部分;但不能,如果 listView 内容不适合页面,我只能水平滚动页面而不是垂直滚动。
这个问题很接近,但不是我要找的:link
谢谢。
【问题讨论】:
-
它应该可以开箱即用,请在此处输入一些代码...
-
我已经添加了我正在使用的布局。谢谢。
-
尝试从单个页面视图中删除所有文本视图,只保留
android:layout_height="match_parent"的列表视图,看看是否可行 -
我已经删除了包含listView的xml文件中的所有textView,但是listView项目上的垂直滚动仍然不起作用。您是否认为 ViewPager 中的包含布局导致了我的问题……但我需要它,它包含页码指示器形状。只有线性布局的 0.85 部分应该垂直滚动。
标签: android android-listview viewpage