上QQ阅读APP看书,第一时间看更新
Creating a new project
If you'd like more details and explanation about these steps, refer to the Creating a new Cardboard project section in Chapter 2, The Skeleton Cardboard Project, and follow along there:
- With Android Studio opened, create a new project. Let's name it
CardboardBox
and target Android 4.4 KitKat (API 19) with an Empty Activity. - Add the Cardboard SDK
common.aar
andcore.aar
library files to your project as new modules, using File | New | New Module.... - Set the library modules as dependencies to the project app, using File | Project Structure.
- Edit the
AndroidManifest.xml
file as explained in Chapter 2, The Skeleton Cardboard Project, being careful to preserve thepackage
name for this project. - Edit the
build.gradle
file as explained in Chapter 2, The Skeleton Cardboard Project, to compile against SDK 22. - Edit the
activity_main.xml
layout file as explained in Chapter 2, The Skeleton Cardboard Project. - Edit the
MainActivity
Java class so that itextends
CardboardActivity
andimplement
s
CardboardView.StereoRenderer
. Modify the class declaration line as follows:public class MainActivity extends CardboardActivity implements CardboardView.StereoRenderer {
- Add the stub method overrides for the interface (using intellisense implement methods or pressing Ctrl + I).
- At the top of the
MainActivity
class, add the following comments as placeholders for variables that we will be creating in this project:CardboardView.StereoRenderer { private static final String TAG = "MainActivity"; // Scene variables // Model variables // Viewing variables // Rendering variables
- Lastly, edit
onCreate()
by adding theCardboadView
instance as follows:@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); CardboardView cardboardView = (CardboardView) findViewById(R.id.cardboard_view); cardboardView.setRenderer(this); setCardboardView(cardboardView); }