A
A
Alexander Dorofeev2016-03-21 10:54:12
Java
Alexander Dorofeev, 2016-03-21 10:54:12

How to render standard views over LibGDX?

You need to display the standard Views over LibGDX . I came across this in the official documentation. I did it, as it was said there, but Fragment with LibGDX at the start of the Activity inflates into FrameLayout , and not in the Activity content, so that Views can be seen . And everything works, but my Views are over The FrameLayout from the Activity layout is not visible, as if the Fragment has become fullscreen anyway and filled the entire space of the Activity. How can I avoid this?
GameActivity layout :

<?xml version="1.0" encoding="utf-8"?>
<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="..."> <!--путь к Activity-->

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <!-- my views...-->

    </RelativeLayout>

    <FrameLayout
        android:id="@+id/game_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </FrameLayout>

</RelativeLayout>

GameActivity code :
public class GameActivity extends AppCompatActivity implements AndroidFragmentApplication.Callbacks {

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

    private void setupGameFragment() {
        GameFragment fragment = new GameFragment();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.game_fragment_container, fragment);
        transaction.commit();
    }

    @Override
    public void exit() {

    }
}

GameFragment code :
public class GameFragment extends AndroidFragmentApplication {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return initializeForView(new GameLauncher());
    }

}

Answer: It was necessary to change the
flag on which LibGDX is drawn . GameFragment code :setZOrderOnTopSurfaceView


public class GameFragment extends AndroidFragmentApplication {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = initializeForView(new GameLauncher(), config);
        setupSurfaceView();
        return view;
    }

    private void setupSurfaceView() {
        if (graphics.getView() instanceof SurfaceView) {
            SurfaceView surfaceView = (SurfaceView) graphics.getView();
            surfaceView.setZOrderOnTop(false);
        }
    }
}

Thanks to Denis Zagaevsky !

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2016-03-21
@TechCloud

Firstly, your game_fragment_container is higher than your views (because it is lower in the markup file), first you should try to swap them.
Secondly, libGDX draws everything in the SurfaceView, if my memory serves me, and it has such a flag setZOrderOnTop , and if it is set (you need to check), then you will not see your content.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question