There is a problem in differentiating Fragment and Activity, this error message:
can not find symbol method addContentView ()
indicates that this method does not exist.
Also the documentation is incorrect, you can not load the map from a snippet with (this):
final RajawaliSurfaceView surface = new RajawaliSurfaceView(this);
This is a basic example of How to load the Rajawali3D map into a Fragment
Create the Activity, adding the Fragment transaction, the Fragment is loaded into the container map_fragment
, defined in the layout act_frag_map
:
public class Map3DFragActivity extends AppCompatActivity {
public RajawaliSurfaceView rajawaliTexture;
Renderer renderer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_frag_map);
setFragment();
}
protected void setFragment() {
FragmentManager fragmentManager = getSupportFragmentManager();
Fragment mapFragment = new FragmentMap();
FragmentTransaction ft =
fragmentManager.beginTransaction();
ft.add(R.id.map_fragment, mapFragment).commit();
}
}
This is the layout that contains a fragment, the name of our fragment class is added in the property android:name
:
act_frag_map
<RelativeLayout 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"
tools:context=".FragmentExampleActivity" >
<fragment
android:id="@+id/map_fragment"
android:name="com.test.FragmentMap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>
</RelativeLayout>
This is the Fragment that creates the Map:
FragmentMap
import org.rajawali3d.surface.RajawaliSurfaceView;
public class FragmentMap extends Fragment {
public RajawaliSurfaceView rajawaliTexture;
Renderer renderer;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_frag_map,
container, false);
rajawaliTexture = (RajawaliSurfaceView) view.findViewById(R.id.rajawali_surface);
renderer = new Renderer(getActivity());
rajawaliTexture.setSurfaceRenderer(renderer);
return view;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // make sure this line exists
}
}
activity_frag_map
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:surfaceview="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<org.rajawali3d.surface.RajawaliSurfaceView
android:id="@+id/rajawali_surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
surfaceview:frameRate="60.0"
surfaceview:renderMode="RENDER_WHEN_DIRTY"/>
</FrameLayout>