LinearLayout 让子级改变焦点上的选择器状态

发布于 2024-12-24 21:40:43 字数 601 浏览 5 评论 0原文

我有一个水平布局,其中调度了一些垂直布局。

我想捕获垂直布局的 onFocusEvent,以便当其中一个获得焦点时,垂直布局中包含的图像和文本视图会更改选择器状态。

我尝试通过捕获事件 OnFocusChange 来测试它,如下所示:

LLContact.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View arg0, boolean hasFocus) {
        // TODO Auto-generated method stub

        if (hasFocus == true) {

            // Has Focus

        } else {

            // Loses focus

        }

        }
    });

但该事件从未被触发。

我将线性布局设置为“FocusableInTouchMode”为 true,将 Focusable 也设置为 true,但似乎该事件从未发生......您有任何线索吗?

提前致谢。

I have a Horizontal Layout in which some vertical layouts are dispatched.

I want to catch the onFocusEvent of my vertical layouts so when one of them gets focus, the image and the textview contained in the vertical layout changes the selector states.

I tried to test it with catching the event OnFocusChange like this :

LLContact.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View arg0, boolean hasFocus) {
        // TODO Auto-generated method stub

        if (hasFocus == true) {

            // Has Focus

        } else {

            // Loses focus

        }

        }
    });

But the event is never triggered.

I set my linear layout to "FocusableInTouchMode" as true, and Focusable as true as well, but it seems the event never happens ... Do you have any clue ?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

演多会厌 2024-12-31 21:40:43

您需要设置管理器 textview 和 imageview 的子级的以下属性:
可聚焦=假;
可点击=假;
focusable in touch mode=false;

并将布局的这些属性设置为 true;

You need to set following properties of childs of manager textview and imageview:
focusable=false;
clickable=false;
focusable in touch mode=false;

and set these properties of layout to true;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文