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


     参数讲解

    setBindStateChangedListener(Component.BindStateChangedListener)

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

    示例

    1. findComponentById(ResourceTable.Id_text_helloworld).setBindStateChangedListener(new Component.BindStateChangedListener() {
    2. @Override
    3. public void onComponentBoundToWindow(Component component) {
    4. //todo 当组件绑定到窗口时调用
    5. }
    6. @Override
    7. public void onComponentUnboundFromWindow(Component component) {
    8. //todo 当组件从窗口解除绑定时调用。
    9. }
    10. });

    【问题描述】

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

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

    【问题解答】

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

    答:

    参考如下链接

    文档中心 | HarmonyOS

    cke_3288.png

    此api从Api Version 7 开始支持

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

    答:

    代码如下

    1. textField.setBindStateChangedListener(new Component.BindStateChangedListener() {
    2. @Override
    3. public void onComponentBoundToWindow(Component component) {
    4. int count1=textField.getLineCount();
    5. Text mytext=findComponentById(ResourceTable.Id_mytext);
    6. mytext.setText("#####行数"+count1);
    7. }
    8. @Override
    9. public void onComponentUnboundFromWindow(Component component) {
    10. }
    11. });

    【问题描述】

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

    【问题解答】

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

    1. findComponentById(ResourceTable.Id_text_helloworld).setBindStateChangedListener(new Component.BindStateChangedListener() {
    2. @Override
    3. public void onComponentBoundToWindow(Component component) {
    4. AnimationImage = findComponentById(ResourceTable.Id_text_helloworld);
    5. AnimationImage.setRotation(0);
    6. AnimatorProperty animator = AnimationImage.createAnimatorProperty();
    7. animator.setCurveType(Animator.CurveType.LINEAR);
    8. animator.setLoopedCount(AnimatorValue.INFINITE);
    9. animator.rotate(360);
    10. animator.setDuration(10000);
    11. animator.start();
    12. }
    13. @Override
    14. public void onComponentUnboundFromWindow(Component component) {
    15. }
    16. });

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

  • 相关阅读:
    数据结构与算法之矩阵: Leetcode 48. 旋转矩阵 (Typescript版)
    cyclictest生成结果统计图
    Git clone The requested URL returned error: 403 错误的解决办法
    java计算机毕业设计师大家教中心管理系统源程序+mysql+系统+lw文档+远程调试
    MyBatis-Plus
    Unity中Shader通道ColorMask
    JAVA- Acwing -求 1+2+...+n
    【深度学习】卷积层填充和步幅以及其大小关系
    SpringCloud实战项目(1)---创建空项目 jdk17
    14.4、SpringWebFlux-1
  • 原文地址:https://blog.csdn.net/weixin_44708240/article/details/126746155