ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

【JAVA UI】【HarmonyOS】 鸿蒙setBindStateChangedListener的基本使用

2022-09-07 15:02:48  阅读:237  来源: 互联网

标签:getLineCount JAVA component void Component HarmonyOS UI 组件 public


​ 参数讲解

setBindStateChangedListener(Component.BindStateChangedListener)

方法说明:该组件是否添加到窗口的组件树上

示例

findComponentById(ResourceTable.Id_text_helloworld).setBindStateChangedListener(new Component.BindStateChangedListener() {
            @Override
            public void onComponentBoundToWindow(Component component) {
                //todo 当组件绑定到窗口时调用
            }
            @Override
            public void onComponentUnboundFromWindow(Component component) {
                //todo 当组件从窗口解除绑定时调用。
            }
        });

 

 

【问题描述】

问题1:调用TextField.getLineCount()获取行数闪退

问题2:怎么使用getLineCount(),

【问题解答】

问题1:调用TextField.getLineCount()获取行数闪退

答:

参考如下链接

https://developer.harmonyos.com/cn/docs/documentation/doc-references/text-0000001054838676#ZH-CN_TOPIC_0000001054838676__getLineCount--

cke_3288.png

此api从Api Version 7 开始支持

问题2:怎么使用getLineCount(),

答:

代码如下

textField.setBindStateChangedListener(new Component.BindStateChangedListener() {
            @Override
            public void onComponentBoundToWindow(Component component) {
                int count1=textField.getLineCount();
                Text mytext=findComponentById(ResourceTable.Id_mytext);
                mytext.setText("#####行数"+count1);
            }

            @Override
            public void onComponentUnboundFromWindow(Component component) {

            }
        });

 

【问题描述】

首页有个动画-安装应用后自动启动动画,执行启动的代码,然后该动画不能启动,单给在点击事件中执行动画的代码,动画生效,这是什么原因?应该怎么处理呢?

【问题解答】

当组件没有添加到窗口的组件树,支持该动画是不生效,需要监听该组件是否添加到窗口的组件树上,代码如下

findComponentById(ResourceTable.Id_text_helloworld).setBindStateChangedListener(new Component.BindStateChangedListener() {
            @Override
            public void onComponentBoundToWindow(Component component) {
                AnimationImage = findComponentById(ResourceTable.Id_text_helloworld);
                AnimationImage.setRotation(0);
                AnimatorProperty animator = AnimationImage.createAnimatorProperty();
                animator.setCurveType(Animator.CurveType.LINEAR);
                animator.setLoopedCount(AnimatorValue.INFINITE);
                animator.rotate(360);
                animator.setDuration(10000);
                animator.start();

            }

            @Override
            public void onComponentUnboundFromWindow(Component component) {

            }
        });

​欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh

标签:getLineCount,JAVA,component,void,Component,HarmonyOS,UI,组件,public
来源: https://www.cnblogs.com/developer-huawei/p/16665442.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有