安卓网络链接每次在电视上都需要两次尝试才能集中注意力



我有一个应用程序,它有一个非常简单的电视布局,由2个网络链接(android:autoLink="web"(和一个文本标签组成。它的渲染图如下:

http://yahoo.com

非聚焦标签

http://google.com

当第一次加载屏幕时,我点击d-pad向下按钮,焦点转到第一个链接(yahoo.com(。然后我再次点击d-padd向下,希望它聚焦在google.com上。相反,屏幕没有改变,也没有显示焦点。如果我再次点击d-pad,焦点最终会到达google.com。这只发生在第一次加载屏幕时,如果我一直向上/向下点击d-pad,则焦点会按预期在2个网络链接之间移动。我正在寻求帮助,弄清楚为什么焦点第一次没有像预期的那样表现。谢谢

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "http://yahoo.com"
android:autoLink="web"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="non focusable label"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "http://google.com"
android:autoLink="web"
/>
</LinearLayout>

看起来你在某个时候失去了焦点。

你需要添加到不应该关注的视图中:

android:focusable="false"
android:focusableInTouchMode="false"

需要添加的第二件事是下一个视图的聚焦方向,需要像这样聚焦:

android:nextFocusDown="@+id/link_two"
android:nextFocusUp="@+id/link_one"

这意味着集中的视图需要有ID。

最终解决方案:

<TextView
android:id="@+id/link_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "http://yahoo.com"
android:autoLink="web"
android:nextFocusDown="@+id/link_two"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="non focusable label"
android:focusable="false"
android:focusableInTouchMode="false"
/>
<TextView
android:id="@+id/link_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "http://google.com"
android:autoLink="web"
android:nextFocusUp="@+id/link_one"
/>

最新更新