Android的ListView中自定义标题

编程入门 行业动态 更新时间:2024-10-11 19:14:05
本文介绍了Android的ListView中自定义标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个自定义列表视图,这是重新可布置(拖放放大器;降),显然滚动。我需要添加一个自定义标题与此列表视图应该与滚动列表。

I have a custom listview, which is re-arrangeable(drag & drop) and obviously scrollable. I need to add a custom header with this listview which should scroll with the list.

我曾尝试listView.addHeaderView(头)与自定义标题布局。但头变为列表重新安排过程中搞砸了。所以我不希望使用addHeaderView(...)。

I have tried "listView.addHeaderView(header)" with a custom header layout. But header becomes messed up during list re-arrangement. So I don't want to use addHeaderView(...).

我也试图把我的活动布局这是一个的LinearLayout,滚动型内,展开列表如下建议 - How我可以把一个ListView成滚动型没有它崩溃?。但是,滚动有些慢,滚动型是在创建列表项重新安排的问题。

I have also tried to put my activity layout which is a LinearLayout, inside a ScrollView and expand the list as suggested here - How can I put a ListView into a ScrollView without it collapsing?. But, scrolling seems slow and ScrollView is creating issue in list item re-arrangement.

那么,有没有其他的方式来实现这种效果呢?我想preFER布局一些解决方案。

So is there any other way to accomplish this effect? I would prefer some solution in layout.

我在Android的UI相当缺乏经验。先谢谢了。

I am fairly inexperienced in Android UI. Thanks in advance.

推荐答案

您可以将头视图添加到列表中,使用下列code,

You can add a Header View to your list, using the following code,

View header = getLayoutInflater().inflate(R.layout.header, null); ListView listView = getListView(); listView.addHeaderView(header); setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice,android.R.id.text1, names));

不过,对于这一点,你需要定义layour的头查看,检查本的链接Android的ListActivity与页眉或页脚

编辑 - 按评论,我想提一提的是,这不是一个很好的做法,使用的ListView 在滚动型。最佳的解决方案,我发现到目前为止是 HeaderView 添加到您的的ListView 。这将是更好,如果OP可以提到,有什么问题,他正面临着与 HeaderView

Edit- As per comment, I would like to mention that, It is not a good practice to use a ListView inside a ScrollView. The best possible solution, I found so far is to add HeaderView to your ListView. It would be better if the OP could mention, what problems he is facing with the HeaderView

如果你想有一个滚动的标题,你一定要与HeaderView去。但是,如果你想拥有的ListView上述静态头,你可以使用一个TextView作为ListView控件的标题。

If you want a scrollable header, you should definitely go with the HeaderView. But if you want to have a static header above the ListView, you could use a TextView as a Heading of the ListView.

更多推荐

Android的ListView中自定义标题

本文发布于:2023-10-30 07:24:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1542170.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   标题   Android   ListView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!