我正在开发一个需要通过蓝牙与其他设备配对的应用程序。我无法以正确的方式显示配对设备列表。我也查看了 android api(蓝牙聊天)中的示例,但我遇到了同样的问题。
已配对设备的列表太大,然后隐藏了列表底部的搜索按钮。
我的 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
您可以在对话框窗口的底部看到一些按钮。
可以限制 ListView 中显示的行数吗?谁能告诉我如何解决这个问题
最佳答案
首先是关于您的代码的一些要点:
layout_weight 仅当对象在某个维度上没有大小时才有意义,即您将 layout_height 或 layout_width 设置为 0,因此这对您的代码没有影响。wrap_content 是毫无意义的,即使可行也是不好的做法。使用“fill_parent”或确定的高度。因此,让我们考虑一下您真正拥有的是什么 - 它只是一个底部带有按钮的列表(是的,您可能在其中有标题或多个数据源,但我们会着手处理)。
以下布局将在顶部为您提供一个 ListView,在底部为您提供一个按钮。 ListView 将占用 Button 未使用的任何空间。请注意在布局中 Button 是如何在 ListView 之前定义的 - 这会导致 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这允许您向其添加 View ,然后您可以将 SackOfViewsAdapter 添加到 MergeAdapter。
这里是一些伪代码,应该完成上面列出的内容。
// This is the adapter we will use for our list with ListView.setAdapter
MergeAdapter listAdapter = new MergeAdapter();
// The first header - you'll need to inflate the actual View (myHeaderView1) from some resource
// using LayoutInflater
List<View> firstHeaderViews = new List<View();
firstHeaderViews.add(myHeaderView1);
SackOfViewsAdapter firstHeaderAdapter = new SackOfViewsAdapter(firstHeaderViews)
// Second header
List<View> secondHeaderViews = new List<View();
secondHeaderViews.add(myHeaderView2);
SackOfViewsAdapter secondHeaderAdapter = new SackOfViewsAdapter(secondHeaderViews);
// Now to add everything to the MergeAdapter
// First goes the first header
listAdapter.addAdapter(firstHeaderAdapter);
// Now your first list
listAdapter.addAdapter(firstListAdapter);
// Now your second header
listAdapter.addAdapter(secondHeaderAdapter);
// Now your second list
listAdapter.addAdapter(secondListAdapter);
// Now set the adapter to the list
myList.setAdapter(listAdapter)
生成的布局应该看起来像like this .请注意,我扩展了列表以显示它如何处理比屏幕更长的列表;该按钮仍然可见。红色框标记了屏幕的边界。
关于android - 限制listview的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7540350/
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
因此,在使用Sphinx时,搜索限制为1000个结果。但是,如果will_paginate生成的结果分页链接超过1000个,请不要考虑这一点,并提供指向超过1000/per_page的页面的链接。设置最大页数或类似内容的明显方法是什么?干杯。 最佳答案 我认为最好将参数:total_entries提交给方法paginate:@posts=Post.paginate(:page=>params[:page],:per_page=>30,:total_entries=>1000)will_paginate将仅为显示1000个结果所需的页
在ruby1.9中,放宽了行结束位置的条件,因此我们现在可以用句号开始一行来显示方法调用。当我们混淆了链式和非链式方法,并希望显示下一个非链式方法的开始位置时,这很方便。如果没有这个新功能,我们能做的最好的可能就是使用缩进:method1(args1).method2(args2).method3(args3)method4(args4).method5(args5).method6(args6)或插入一个空行。但这很不方便,因为我们必须注意缩进,同时,不要忘记在每个方法调用之后加上链中最后一个方法调用之后的句点。正因为如此,我制造了很多错误,要么有一个额外的周期,要么有一个缺失的
我知道我们可以做到:sidekiq_optionsqueue:"Foo"但在这种情况下,Worker只分配给一个队列:“Foo”。我需要在特定队列中分配作业(而不是worker)。使用Resque很容易:Resque.enqueue_to(queue_name,my_job)另外,为了并发问题,我需要限制每个队列的Worker数量为1。我该怎么做? 最佳答案 您可能会使用https://github.com/brainopia/sidekiq-limit_fetch然后:Sidekiq::Client.push({'class'=>
业务逻辑:用户每天只能为日记创建一个条目。在创建条目之前,它必须查询记录以确定是否已经为今天创建了条目。我正在寻找解决此问题的最佳方法的建议。我对如何在客户端实现它有一些想法,但我真的很想在模型层进行验证。任何帮助将不胜感激。 最佳答案 在日志表上创建唯一索引:add_index:journal_entries,[:user_id,:created_on],unique:true然后只能创建一条具有给定user_id和日期的记录,如果违反,数据库将引发异常。请注意,created_on必须是date列,而不是datetime。这是唯
我的迁移看起来像这样classCreateQuestionings现在,当我运行$rakedb:migrate:reset时,在我的db/schema.rb中看不到限制:create_table"questionings",force::cascadedo|t|t.text"body",null:falseend我做错了吗还是这是一个错误?顺便说一下,我使用的是rails5.0.0.beta3和ruby2.3.0p0。 最佳答案 t.text在PostgreSQL和textdoesn'tallowforsizelimits中生成
平时开发中我们经常会遇到这样的需求,在一个不限高度的盒子中会有很多内容,如果全部显示用户体验会非常不好,所以可以先折叠起来,当内容达到一定高度时,显示展开更多按钮,点击即可显示全部内容,先来看看效果图: 这样做用户体验瞬间得到提升,接下来看看具体细节。0">主要操作在内容这里{{item.username}},……展开更多样式大家可依据自己项目需求进行设计,这里就不贴了,主要说几个关键的。1、在data中定义三个属性isShowMore:false, //控制展开更多的显示与隐藏textHeight:null, //框中内容的高度status:false, //内容状态是否打开2.计算内容是否
在Ruby中如何限制String#gsub的替换次数?在PHP中,这可以通过preg_replace轻松完成,它接受一个参数来限制替换,但我不知道如何在Ruby中做到这一点。 最佳答案 您可以在gsub循环中创建一个计数器并递减它。str='aaaaaaaaaa'count=5pstr.gsub(/a/){ifcount.zero?then$&elsecount-=1;'x'end}#=>"xxxxxaaaaa" 关于ruby-使用gsub时如何限制替换次数?,我们在StackOverf
假设我希望Ruby进程使用的CPU不超过15%。是否可以?怎么办? 最佳答案 您可以尝试使用Process.setrlimit来自标准核心:Setstheresourcelimitoftheprocess.这看起来只是setrlimit的包装器来自C库,因此它可能仅在Unix-ish平台上可用。setrlimit不支持CPU百分比限制,但它支持以秒为单位限制CPU时间。如果您只是想让您的Ruby进程不占用整个CPU,那么您可以尝试使用Process.setpriority来调整它的优先级。这只是libc的setpriority的包装
我正在使用出色的Foggem来访问Rackspace云文件服务。我面临的挑战是,我正在努力使访问CloudFiles的服务保持轻量级,而且Fog似乎通过其灵active具有很多我永远不需要的依赖项和代码。有没有人尝试过构建Fog的精简副本,只包含一部分提供者,从而限制依赖性?例如,专门针对Rackspace云文件API,我希望能够在没有net-ssh、net-scp、nokogirigems以及亚马逊、Rackspace和其他20个未使用的提供商的所有未使用代码的情况下处理所有内容用过的。我希望避免在每次这些未使用的提供程序之一发现错误时升级gem,同时减少我的内存占用。如果任何人在这