在哪里我将sceneform_hand_phone.png图像更改为自定义图像?这是带有ARCore的Android库场景中使用的手的图像。
谢谢
答案 0 :(得分:2)
HelloSceneformActivity.java :
public class HelloSceneformActivity extends AppCompatActivity {
private ArFragment arFragment;
private View phoneImage;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ux);
// Get AR fragment from layout
arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);
// Disable plane discovery hand motion animation
arFragment.getPlaneDiscoveryController().hide();
ViewGroup container = findViewById(R.id.sceneform_hand_layout);
container.removeAllViews();
// Create the new plane discovery animation and add it to the hand layout.
phoneImage = getLayoutInflater().inflate(R.layout.hand_layout, container, true);
// Set the instructions view in the plane discovery controller.
arFragment.getPlaneDiscoveryController().setInstructionView(phoneImage);
}
}
activity_ux.xml :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sceneform_hand_layout"
android:clipChildren="false"
tools:context=".HelloSceneformActivity">
<fragment class="com.google.ar.sceneform.ux.ArFragment"
android:id="@+id/ux_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
将自定义手部动画放置在其自己的布局文件中(必须动态创建), hand_layout.xml :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.ar.sceneform.ux.HandMotionView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foregroundGravity="center"
android:scaleType="center"
android:src="@drawable/YOURIMAGE" />
</FrameLayout>
build.gradle :
buildscript {
repositories {
google()
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.ar.sceneform:plugin:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenLocal()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
答案 1 :(得分:0)
class ExampleFragment : ArFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState);
...
val customDiscoveryView = <inflate custom view>
planeDiscoveryController.setInstructionView(customDiscoveryView)
}
}