Android:如何避免标题在listview中滚动,Android?
我有一个列表视图,在这里我将headerview添加到该列表中。一切都很好,但当我滚动列表headerview时,它也会随着列表一起移动,所以我想避免headerview滚动,我的意思是当我的列表到达topview(标题栏)时,我必须只滚动列表,headerview必须保持标题栏的底部Android:如何避免标题在listview中滚动,Android?,android,listview,header,Android,Listview,Header,我有一个列表视图,在这里我将headerview添加到该列表中。一切都很好,但当我滚动列表headerview时,它也会随着列表一起移动,所以我想避免headerview滚动,我的意思是当我的列表到达topview(标题栏)时,我必须只滚动列表,headerview必须保持标题栏的底部 有人能给我一个解决办法吗?我不确定我是否正确理解了你的要求。 所以我知道你有点像 <ListView> <Header /> <Item /> <Item /> &
有人能给我一个解决办法吗?我不确定我是否正确理解了你的要求。 所以我知道你有点像
<ListView>
<Header />
<Item />
<Item />
<Item />
</ListView>
你为什么不这样做
<Header />
<ListView>
<Item />
<Item />
<Item />
</ListView>
?将视图直接添加到列表视图上方的布局中,而不是添加标题视图。
我实现了我的所有列表视图,如下所示,所有列表视图都工作grt..使用以下布局代替标题:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
--> Your header layout here
</LinearLayout>
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" />
</LinearLayout>
-->您的标题布局在这里
需要注意的重要事项:
- ListView的id必须是
,才能使用ListActivity@android:id/list
- 使用0高度并将重量设置为1
下面是一个布局示例,其中包含标题视图和列表视图对于我来说,在我的列表视图之前包含一个名为
的标记时,效果很好,
代码是这样的
<include layout="@layout/stationlist_header"/>
<ListView
android:id="@+id/mylist"
android:layout_width="match_parent"
android:layout_height="210dp"
android:layout_gravity="bottom"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
>
</ListView>
对于一个标题,这是个好主意。但如果我有,相同的listview会有不同的列表模式。我给了一个headerview,每个模式对应一个header,很好。但如果我有,相同的listview会有不同的列表模式。我为每个模式提供了一个headerview。一个问题是,如何将标题与其下划线数据对齐?这很有效。但是对于我来说,listview可以有一个可以滚动的页眉和页脚,这似乎很奇怪。很难想象有一个用例会让它们滚动。我希望在ListView中添加一个新属性,用于锁定页眉和页脚。
<include layout="@layout/stationlist_header"/>
<ListView
android:id="@+id/mylist"
android:layout_width="match_parent"
android:layout_height="210dp"
android:layout_gravity="bottom"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
>
</ListView>