根據(jù)官方文檔
- 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'
}
- 初始化SoLoader
首先,初始化SoLoader。Litho依賴于SoLoader來幫助由底層布局引擎Yoga提供的庫。
在Application中初始化就可以了
SoLoader.init(this, false);
- 運行
之后在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);
最終效果