Proteus は、Android のLayoutInflater
のドロップイン代替品となることを目的としています。ただし、APK にバンドルされているコンパイル済み XML レイアウトとは異なり、Proteus は実行時にレイアウトをインフレートします。 Proteus を使用すると、バックエンド (WebView なし) からアプリのレイアウトを制御できます。 findViewById
への定型コードを忘れて、それをTextView
にキャストしてからsetText()
ます。 Proteus にはランタイム データ バインディングとフォーマッタがあります。独自のカスタム ビュー、属性、関数にプラグインして、プロテウスを要件に合わせて調整します。
// Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
google ( )
jcenter ( )
maven { url 'https://jitpack.io' }
}
}
// Add in your app level dependency
dependencies {
implementation 'com.github.flipkart-incubator.proteus:proteus-core:5.0.1'
implementation 'com.github.flipkart-incubator.proteus:gson-adapter:5.0.1'
implementation 'com.github.flipkart-incubator.proteus:cardview-v7:5.0.1'
implementation 'com.github.flipkart-incubator.proteus:design:5.0.1'
implementation 'com.github.flipkart-incubator.proteus:recyclerview-v7:5.0.1'
implementation 'com.github.flipkart-incubator.proteus:support-v4:5.0.1'
}
XML
でレイアウトを記述する代わりに、 proteusではレイアウトはJSON
で記述され、実行時にネイティブ Android UI をインフレートするために使用できます。 JSON
レイアウトは、どこでも (デバイス上、サーバー上など) ホストできます。
レイアウトは、 XML と同様に、ビューの階層を定義します。
Data (オプション) はデータ バインディングを定義します。これらのデータ バインディングは、Android のデータ バインディング ライブラリに似ています。
layout
とdata
ProteusLayoutInflater
に渡し、ネイティブ ビュー階層を取得します。
実際の動作を確認するには、このビデオをご覧ください。
{
"type" : "LinearLayout" ,
"orientation" : "vertical" ,
"padding" : "16dp" ,
"children" : [ {
"layout_width" : "200dp" ,
"gravity" : "center" ,
"type" : "TextView" ,
"text" : "@{user.profile.name}"
} , {
"type" : "HorizontalProgressBar" ,
"layout_width" : "200dp" ,
"layout_marginTop" : "8dp" ,
"max" : 6000 ,
"progress" : "@{user.profile.experience}"
} ]
}
{
"user" : {
"profile" : {
"name" : "John Doe" ,
"experience" : 4192
}
}
}
ProteusView view = proteusLayoutInflater . inflate (< layout >, < data >);
container . addView ( view . getAsView ());
デモ アプリを使用すると、proteus を試してみることができるほか、内部構造をよりよく理解するのにも役立ちます。
npm start
実行しますいじる準備はできています
貢献する最も簡単な方法は、リポジトリをフォークし、変更を加えてプル リクエストを作成することです。
アパッチ v2.0
プロテウスを使用している場合は、できること、できないこと、しなければならないことを確認してください。
ここで寄稿者をチェックできますが、ご希望の場合は当社までご連絡ください。メールをお送りください。
Proteus の StackOverflow で私たちを見つけてください。
Android Studio 用のこのプラグイン (ベータ版) をダウンロードします。有効にすると、任意の Android XML リソース ファイルを選択し、 [ツール] > [Proteus] > [XML を JSON に変換]に移動できます。