Implement Map Globo Rajawali in a fragment Andriod

2

Good morning, I have problems with incorporating the earth map in an android fragment From an activity it is done in this way:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final RajawaliSurfaceView surface = new RajawaliSurfaceView(this);
    surface.setFrameRate(60.0);
    surface.setRenderMode(IRajawaliSurface.RENDERMODE_CONTINUOUSLY);

    // Add mSurface to your root view
    addContentView(surface, new  ActionBar.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT));

    renderer = new Renderer(this);
    surface.setSurfaceRenderer(renderer);
}

But when I want to do it in a fragment I get the line error

addContentView(surface, new  ActionBar.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT));

Error: (81, 9) error: can not find symbol method addContentView (RajawaliSurfaceView, LayoutParams)

    
asked by mauricio 17.03.2016 в 19:18
source

1 answer

1

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>
    
answered by 18.03.2016 в 17:44