使用 ViewRenderable 我正在渲染布局文件。我为布局文件提供了固定的宽度和高度
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="500dp"
android:layout_height="50dp"
android:background="@android:color/transparent">
// Add design
</android.support.constraint.ConstraintLayout>
现在我将布局构建为 ViewRenderable
// Build a renderable from a 2D View.
CompletableFuture<ViewRenderable> meterOne =
ViewRenderable.builder().setView(this, R.layout.meter).build();
CompletableFuture.allOf(circle,
meterOne, meterTwo)
.handle(
(notUsed, throwable) -> {
// When you build a Renderable, Sceneform loads its resources in the background while
// returning a CompletableFuture. Call handle(), thenAccept(), or check isDone()
// before calling get().
if (throwable != null) {
DemoUtils.displayError(this, "Unable to load renderable", throwable);
return null;
}
try {
Meters.add(meterOne.get());
} catch (InterruptedException | ExecutionException ex) {
DemoUtils.displayError(this, "Unable to load renderable", ex);
}
之后我需要将此ViewRenderable
对象渲染到节点中
Node sunVisual = new Node();
sunVisual.setParent(sun);
sunVisual.setRenderable(Meters.get(0)); // View
sunVisual.setLocalScale(new Vector3(0.5f, 0.5f, 0.5f));
现在我需要在 sunVisual 节点的右侧添加另一个节点
Node node = new Node();
node.setParent(sunVisual );
node.setRenderable(Meters.get(1));
node.setLocalPosition(new Vector3(2.0f, 0.0f, 0.0f));
此代码在 google pixel 2 设备上运行良好,但我在 nokia x6 设备上的空间很小
如何以米为单位获取渲染视图的宽度和高度?
如何根据父节点渲染视图大小将本地位置设置在父节点右侧
提前帮我解决这个问题谢谢