場合によっては、XML と RemoteViews
を使用してビューを提供することもできます。Glance なしですでに機能を実装しているか、現在の Glance API ではまだ利用できないか、実現できない可能性があります。このような状況のために、Glance には相互運用 API である AndroidRemoteViews
が用意されています。
AndroidRemoteViews
コンポーザブルを使用すると、RemoteViews
を他のコンポーザブルと一緒に配置できます。
val packageName = LocalContext.current.packageName Column(modifier = GlanceModifier.fillMaxSize()) { Text("Isn't that cool?") AndroidRemoteViews(RemoteViews(packageName, R.layout.example_layout)) }
Glance を使用しない場合と同様に RemoteViews
を作成、定義し、パラメータとして渡します。
さらに、コンポーザブル用の RemoteViews
コンテナを作成できます。
AndroidRemoteViews( remoteViews = RemoteViews(packageName, R.layout.my_container_view), containerViewId = R.id.example_view ) { Column(modifier = GlanceModifier.fillMaxSize()) { Text("My title") Text("Maybe a long content...") } }
この場合、「container」を含むレイアウトが定義された ID とともに渡されます。このコンテナは、定義されたコンテンツの配置に使用されるため、ViewGroup
にする必要があります。