
配对设备列表将变大,然后隐藏位于列表底部的搜索按钮.
我的xml代码与示例非常相似:
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" > <TextVIEw androID:ID="@+ID/Listpaired_devices" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:text="@string/Title_paired_devices" androID:visibility="gone" androID:background="#666" androID:textcolor="#fff" androID:paddingleft="5dp" /> <ListVIEw androID:ID="@+ID/paired_devices" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:stackFromBottom="true" androID:layout_weight="1" /> <TextVIEw androID:ID="@+ID/List_new_devices" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:text="@string/Title_other_devices" androID:visibility="gone" /> <ListVIEw androID:ID="@+ID/new_devices" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:stackFromBottom="true" androID:layout_weight="2" /> <button androID:ID="@+ID/btscan" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:text="@string/btscan" /></linearLayout>
但是我无法在底部显示搜索按钮.
在这里我的屏幕:
My Screen
您可以在对话框窗口的底部看到一些按钮.
可以限制列表视图中显示的行数吗?任何人都可以告诉我如何解决这个问题
解决方法 首先是关于你的代码的几点:> layout_weight仅在对象在特定维度中没有大小时才有意义,即将layout_height或layout_wIDth设置为0,因此这对您的代码没有影响.
>将ListVIEw的高度设置为wrap_content是没有意义的,即使它起作用也是不好的做法.使用’fill_parent’或确定的高度.
>按钮被隐藏,因为根据上面的点,您创建的ListVIEw没有预定义的大小,因此占用尽可能多的空间,将按钮从屏幕上移开.
所以让我们考虑一下你真正拥有的东西 – 它只是一个单独的列表,底部有一个按钮(是的,你可能有标题或多个数据源,但我们会进入那个).
以下布局将在顶部提供ListVIEw,在底部提供button. ListVIEw将占用button未使用的任何空间.注意如何在布局中的ListVIEw之前定义button – 这会导致AndroID在考虑ListVIEw之前计算按钮占用的高度.然后它为ListVIEw提供剩余的高度.
<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" > <button androID:ID="@+ID/btscan" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:layout_alignParentBottom="true" androID:text="@string/btscan" /> <ListVIEw androID:ID="@+ID/all_devices" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:layout_above="@ID/btscan" androID:stackFromBottom="true" /> </relativeLayout>
这就是布局.现在让我们考虑列表的实际内容:您有一个标题,后面跟着一个配对设备列表,然后是另一个标题,然后是新设备列表.
您可以使用单个适配器创建它 – Commonsware提供了一个非常好的实现,称为MergeAdapter,但您可以编写自己的代码. MergeAdapter不会直接为您提供视图(例如标题),但幸运的是Commonsware还提供了允许您添加视图的SackOfViewsAdapter,然后您可以将SackOfVIEwsAdapter添加到MergeAdapter.
这是一些伪代码,应该完成上面概述的内容.
// This is the adapter we will use for our List with ListVIEw.setAdapterMergeAdapter listadapter = new MergeAdapter();// The first header - you'll need to inflate the actual VIEw (myheaderVIEw1) from some resource// using LayoutInflaterList<VIEw> firstheaderVIEws = new List<VIEw();firstheaderVIEws.add(myheaderVIEw1);SackOfVIEwsAdapter firstheaderAdapter = new SackOfVIEwsAdapter(firstheaderVIEws)// Second headerList<VIEw> secondheaderVIEws = new List<VIEw();secondheaderVIEws.add(myheaderVIEw2);SackOfVIEwsAdapter secondheaderAdapter = new SackOfVIEwsAdapter(secondheaderVIEws);// Now to add everything to the MergeAdapter// First goes the first headerlistadapter.addAdapter(firstheaderAdapter);// Now your first Listlistadapter.addAdapter(firstlistadapter);// Now your second headerlistadapter.addAdapter(secondheaderAdapter);// Now your second Listlistadapter.addAdapter(secondlistadapter);// Now set the adapter to the ListmyList.setAdapter(listadapter)
生成的布局应该看起来像like this.注意我扩展了列表以显示它的行为与列表长于屏幕的行为;按钮仍然可见.红色框标记屏幕的边界.
总结以上是内存溢出为你收集整理的android – 限制listview的行数全部内容,希望文章能够帮你解决android – 限制listview的行数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)