【JAVA UI】【HarmonyOS】 鸿蒙setBindStateChangedListener的基本使用
2022/9/8 1:23:01
本文主要是介绍【JAVA UI】【HarmonyOS】 鸿蒙setBindStateChangedListener的基本使用,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
参数讲解
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--
此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
这篇关于【JAVA UI】【HarmonyOS】 鸿蒙setBindStateChangedListener的基本使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-01为什么公共事业机构会偏爱 TiDB :TiDB 数据库在某省妇幼健康管理系统的应用
- 2024-04-26敏捷开发:想要快速交付就必须舍弃产品质量?
- 2024-04-26静态代码分析的这些好处,我竟然都不知道?
- 2024-04-26你在测试金字塔的哪一层?(下)
- 2024-04-26快刀斩乱麻,DevOps让代码评审也自动起来
- 2024-04-262024年最好用的10款ER图神器!
- 2024-04-2203-为啥大模型LLM还没能完全替代你?
- 2024-04-2101-大语言模型发展
- 2024-04-17基于SpringWeb MultipartFile文件上传、下载功能
- 2024-04-14个人开发者,Spring Boot 项目如何部署