Litho 学习记录(1)

根据官方文档

  1. gradle导入(准备工作)
    // Litho
    compile 'com.facebook.litho:litho-core:0.2.0'
    compile 'com.facebook.litho:litho-widget:0.2.0'
    provided 'com.facebook.litho:litho-annotations:0.2.0'

    annotationProcessor 'com.facebook.litho:litho-processor:0.2.0'

    // SoLoader
    compile 'com.facebook.soloader:soloader:0.2.0'

    // Optional
    // For debugging
    debugCompile 'com.facebook.litho:litho-stetho:0.2.0'

    // For integration with Fresco
    compile 'com.facebook.litho:litho-fresco:0.2.0'

    // For testing
    // testCompile 'com.facebook.litho:litho-testing:0.2.0'

PS:
Android Support需要更新到25.3.1
testCompile 'com.facebook.litho:litho-testing:0.2.0'导入的时候会报

Error:Conflict with dependency 'com.google.code.findbugs:jsr305' in project ':app'. Resolved versions for app (2.0.1) and test app (3.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

参见
在APP层级下的build.gradle中增加

configurations.all {
    resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
    //resolutionStrategy.force 'com.google.code.findbugs:jsr305:2.0.1'
}
  1. 初始化SoLoader
    首先,初始化SoLoader。Litho依赖于SoLoader来帮助由底层布局引擎Yoga提供的库。
    在Application中初始化就可以了
SoLoader.init(this, false);
  1. 运行
    之后在Activity中加入预定义的Litho Text控件
final ComponentContext c = new ComponentContext(this);

    final LithoView lithoView = LithoView.create(
        this /* context */, 
        Text.create(c)
            .text("Hello, World!")
            .textSizeDip(50)
            .build());
        
    setContentView(lithoView);
最终效果

Litho API

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Day1: 在代码中通过R.string.hello_world可以获得该字符串的引用; 在XML中通过@stri...
    冰凝雪国阅读 1,441评论 0 5
  • 1、Throwable接口中的getStackTrace()方法(或者Thread类的getStackTrace(...
    柒黍阅读 703评论 0 1
  • 黑马程序员的视频: 只要精通一门技能就能防身,切不可范范而学不可只懂皮毛。 Log.v() 最低级,打印意义最小的...
    lwwlsky阅读 1,149评论 0 2
  • 不怕跌倒,所以飞翔 组件化开发 参考资源 Android组件化方案 为什么要组件化开发 解决问题 实际业务变化非常...
    笔墨Android阅读 3,006评论 0 0
  • EnglishVersion ->_->:https://github.com/jiang111/awesome-...
    聂顺阅读 1,250评论 0 4