加入收藏 | 设为首页 | 会员中心 | 我要投稿 大连站长网 (https://www.0411zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 教程 > 正文

跨平台自适应布局yoga特性详解

发布时间:2021-05-22 17:05:06 所属栏目:教程 来源:互联网
导读:副标题#e# yoga是facebook打造的一个跨IOS、Android、Window平台在内的布局引擎,兼容Flexbox布局方式,让界面更加简单。 Yoga官网:https://facebook.github.io/yoga/ 官网上描述的特性包括: 完全兼容Flexbox布局,遵循W3C的规范 支持java、C#、Objective
副标题[/!--empirenews.page--]

yoga是facebook打造的一个跨IOS、Android、Window平台在内的布局引擎,兼容Flexbox布局方式,让界面更加简单。

Yoga官网:https://facebook.github.io/yoga/

官网上描述的特性包括:

完全兼容Flexbox布局,遵循W3C的规范

支持java、C#、Objective-C、C四种语言

底层代码使用C语言编写,性能不是问题

支持流行框架如React Native

目前在已开源的鸿蒙组件(https://gitee.com/openharmony-tpc/yoga)的功能现状如下:

native层和接口已经打通

支持自定义xml属性来控制布局(通过YogaLayout)

设置布局中不支持Image控件(onDrawCanvas暂不支持主动回调,所以yoga没办法扫描到它),请使用Text控件替代

不支持VirtualYogaLayout

如何使用

首先我们在MainAbility中定义界面路由。

public class MainAbility extends Ability { 

    @Override 

    public void onStart(Intent intent) { 

        super.onStart(intent); 

        super.setMainRoute(MainAbilitySlice.class.getName()); 

        addActionRoute("action.dydrawnode.slice", DynamicsDrawNodeSlice.class.getName()); 

        addActionRoute("action.showrow.slice", ShowRowAbilitySlice.class.getName()); 

        addActionRoute("action.inflate.slice", BenchmarkInflateAbilitySlice.class.getName()); 

    } 

然后我们来到MainAbilitySlice,其实就是做了一个向其他界面跳转的动作,并提前加载yoga的so库。

public class MainAbilitySlice extends AbilitySlice { 

 

 

 

    static { 

        System.loadLibrary("yoga"); 

        System.loadLibrary("yogacore"); 

        System.loadLibrary("fb"); 

    } 

 

 

 

    @Override 

    public void onStart(Intent intent) { 

        super.onStart(intent); 

        setUIContent(ResourceTable.Layout_main_layout); 

 

        Button btn0= (Button) findComponentById(ResourceTable.Id_btn_1); 

        btn0.setClickedListener(component -> { 

            Intent intent1 = new Intent(); 

            Operation operation = new Intent.OperationBuilder() 

                    .withAction("action.dydrawnode.slice") 

                    .build(); 

            intent1.setOperation(operation); 

            startAbilityForResult(intent1, 1); 

        }); 

 

        Button btn2= (Button) findComponentById(ResourceTable.Id_btn_2); 

        btn2.setClickedListener(component -> { 

            Intent intent1 = new Intent(); 

            Operation operation = new Intent.OperationBuilder() 

(编辑:大连站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!