Android:ListView 中的 QuickContactBadge
首先是场景:
我有一个列表,其中每个项目都有联系人的照片和一些文本。我想单击图像并调出 QuickContactBadge
。徽章由以下 XML 片段定义
<QuickContactBadge android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/badge"
android:layout_alignParentBottom="true"></QuickContactBadge>
我尝试过但失败了:
- 定义一个可重用徽章并在所有情况下重用它。列表和徽章都放置在
RelativeLayout
中, - 为每个列表项定义一个徽章。该项目使用
RelativeLayout
我看到了什么:
基本上什么也没有。代码获取有效的徽章实例,然后应用以下逻辑
contactPhoto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
Log.d(TAG, "Image click");
if (badge != null) {
badge.assignContactFromEmail("[email protected]", true);
badge.setMode(ContactsContract.QuickContact.MODE_SMALL);
badge.bringToFront();
}
}
});
当我单击时,我可以单步执行 onClick
处理程序中的代码,但徽章从未出现
问题:
QuickContactBadge
是否会 出现?有什么放置逻辑吗?当我单击图像时,我是否需要计算徽章位置并重新调整,还是它是内置的?- 是否有可能实现我上面描述的内容(列表中显示的图像徽章)以及我做错了什么(或丢失)
First the scenario:
I have a list where each item has a photo of a contact and some text. I would like to click on the image and bring up the QuickContactBadge
. Badge is defined by the following XML snippet
<QuickContactBadge android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/badge"
android:layout_alignParentBottom="true"></QuickContactBadge>
What I tried and failed:
- Define one reusable badge and reuse it for all cases. Both list and badge are placed into
RelativeLayout
- Have one badge defined per each list item. The item uses
RelativeLayout
What do I see:
Basically nothing. The code gets valid badge instance and then I apply the following logic
contactPhoto.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
Log.d(TAG, "Image click");
if (badge != null) {
badge.assignContactFromEmail("[email protected]", true);
badge.setMode(ContactsContract.QuickContact.MODE_SMALL);
badge.bringToFront();
}
}
});
As I click I can step through the code in onClick
handler yet the badge never comes up
The questions:
- Does
QuickContactBadge
have any placement logic? When I click on the image do I need to calculate badge position and readjust or is it built-in? - Is it possible to achieve what I describe above (badge for images displayed in the list) and what I'm doing wrong (or missing)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
中止!中止!
基本上我完全误解了徽章是什么以及如何使用它。我想做的是检测图像上的点击并调用徽章。这从根本上是错误的,因为我所需要做的只是在代码中使用
QuickContactBadge
而不是ImageView
。当我用项目中的徽章替换图像后,XML 魔法就自动出现了。据说 - 可以使用代码弹出徽章,请参阅 this关于如何做到这一点的文章
Abort! Abort!
Basically I totally misunderstood what the badge is and how to use it. What I was trying to do is to detect click on image and call the badge. This is fundamentally wrong since all I needed to do was to simply use
QuickContactBadge
INSTEAD ofImageView
in my code. After I replaced images with badges in the item XML magic was automatically there.Said that - it is possible to pop the badge using the code, refer to this article on how to do it