AR应用模拟器中手持手机图标遮挡场景点问题求助
Hey there, let's work through this AR Sceneform headache you're dealing with—those issues with the hand-held phone icon blocking your view and the unstable scene after it disappears are super common when testing AR on emulators. Here's how to fix them:
1. Get Rid of the Annoying Hand-Held Icon
That icon is the default plane discovery guide built into ArFragment, designed to prompt users to move their device to scan for surfaces. To hide it (or disable it entirely), add this code to your MainActivity:
Kotlin Code
override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val arFragment = supportFragmentManager.findFragmentById(R.id.jaguar_fragment) as ArFragment // Hide the guide icon immediately arFragment.planeDiscoveryController.hide() // If you want to disable it completely so it never shows up arFragment.planeDiscoveryController.setInstructionView(null) }
Java Code
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ArFragment arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.jaguar_fragment); // Hide the guide icon arFragment.getPlaneDiscoveryController().hide(); // Disable it permanently arFragment.getPlaneDiscoveryController().setInstructionView(null); }
2. Stabilize the AR Scene in the Emulator
Emulators aren't real devices, so AR tracking can be flaky. Try these steps to make it more reliable:
- Use an AR-enabled emulator image: When creating your AVD, pick a system image marked with "Google Play" and "AR support" (like Google Play Intel x86 Atom_64 System Image).
- Enable a virtual AR scene: Open the emulator's extended controls (the three-dot button), go to the AR tab, and select a pre-built virtual scene (e.g., "Living Room"). This gives the emulator a stable environment to track.
- Check Sceneform version compatibility: If you're using an older Sceneform version, it might clash with newer emulator systems. Stick to the latest stable version of Sceneform (note: Sceneform has moved to a CameraX + ARCore combo for newer projects, but adjust based on your setup).
3. Ensure Your Scene Loads Only When Tracking is Stable
That one-time successful display suggests your scene might be loading before the AR session is fully ready. Wait for tracking to stabilize before adding your content:
Kotlin Example
arFragment.arSceneView.scene.addOnUpdateListener { frameTime -> val session = arFragment.arSceneView.session ?: return@addOnUpdateListener if (!session.isTrackingEnabled) { return@addOnUpdateListener } // Load your scene content here—this ensures it only shows up when AR is stable }
Wrap-Up
Start by hiding the guide icon to unblock your view, then tweak the emulator's AR settings for better stability, and finally delay your scene load until tracking is working properly. That should get your AR scene displaying consistently.
内容的提问来源于stack exchange,提问作者Andrey Molochko

