如何指示列表视图项处于焦点?
我实现了自定义列表视图,但现在没有任何视觉反馈表明已选择元素。我认为这很简单,但我找不到任何内容——任何人都可以提供有关如何将默认 UI 元素焦点行为应用于我的列表视图项目的提示吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true">
<TextView android:id="@+id/list_item"
android:layout_gravity="center_vertical"
android:layout_width="0dip"
android:layout_weight="1.0"
android:textSize="20sp"
android:textColor="#FFFFFFFF"
android:layout_height="wrap_content"
android:padding="20dp"/>
</LinearLayout>
从到目前为止我收到的回复来看,我认为我应该澄清我正在尝试做的事情:我想模仿列表视图项(在标准 UI 中)在长按时的行为。当你扔过它时,它实际上并没有做任何事情,但是在触摸该物品并按住它任何时间后,它会变成颜色(在我的例子中为橙色),然后快速转变为白色。
而且,经过进一步检查,我认为只有在添加上下文菜单时才可能发生这种情况 - 我将尝试一下并使用结果进行编辑。
I implemented a custom list view, but now there's no visual feedback that an element has been selected. I think this is trivial but I can't find anything on it -- can anyone provide tips on how to apply a default UI element-in-focus behavior to my listview items?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true">
<TextView android:id="@+id/list_item"
android:layout_gravity="center_vertical"
android:layout_width="0dip"
android:layout_weight="1.0"
android:textSize="20sp"
android:textColor="#FFFFFFFF"
android:layout_height="wrap_content"
android:padding="20dp"/>
</LinearLayout>
From what responses I've gotten so far, I think I should clarify what I'm trying to do: I want to mimic the behavior that a listview item does (in the standard UI) when long-pressed. When you fling through it, it doesn't really do anything, but upon touching the item and holding it for any time at all, it turns colors [orange, in my case] and then quickly transitions to white.
And, upon further inspection, I think this might happen only when adding a Context Menu -- I'll try it out and edit this with the results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能需要查看有关触摸模式的文章。
You might want to take a look at the article on Touch Mode.
执行此操作的方法是添加上下文菜单。这样就能达到我想要的效果了。
The way to do this is by adding a context menu. That will bring about my desired effect.
您可以尝试为列表视图行背景设置可绘制选择器。
可绘制对象需要是这样的:
另外,尝试使用RelativeLayout 而不是LinearLayout。
You can try setting a selector drawable for your listview row background.
The drawable needs to be something like this:
Also, try out RelativeLayout instead of LinearLayout.