Libgdx Resizing Problem

I am trying to fill the resize function that comes with Libgdx to fit all of the android screens.

I have been searching for a solution for about an hour and a half but have none. The best solution so far is this tutorial: http://www.java-gaming.org/index.php?topic=25685.0 but when I run it on my Galaxy S3 the buttons are really tiny and just overall the whole game is tiny where on the desktop version it is big and the way I want it to be. My resize code right now is:


        @Override
	public void resize(int width, int height) {
        float aspectRatio = (float)width/(float)height;
        float scale = 2f;
        Vector2 crop = new Vector2(0f, 0f); 
        if(aspectRatio > ASPECT_RATIO)
        {
            scale = (float)height/(float)VIRTUAL_HEIGHT;
            crop.x = (width - VIRTUAL_WIDTH*scale)/2f;
        }
        else if(aspectRatio < ASPECT_RATIO)
        {
            scale = (float)width/(float)VIRTUAL_WIDTH;
            crop.y = (height - VIRTUAL_HEIGHT*scale)/2f;
        }
        else
        {
            scale = (float)width/(float)VIRTUAL_WIDTH;
        }

        float w = (float)VIRTUAL_WIDTH*scale;
        float h = (float)VIRTUAL_HEIGHT*scale;
        viewport = new Rectangle(crop.x, crop.y, w, h);
    }

My render code is:


        @Override
	public void render() {
		// update camera
        camera.update();

        // set viewport
        Gdx.gl.glViewport((int) viewport.x, (int) viewport.y,
                          (int) viewport.width, (int) viewport.height);

        // clear previous frame
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
        
	    ScreenManager.updateScreen();
	    
	    sb.begin();
	    ScreenManager.renderScreen(sb);
	    sb.end();
	}

And my variables are:


        private static final int VIRTUAL_WIDTH = 600;
	private static final int VIRTUAL_HEIGHT = 800;
	private static final float ASPECT_RATIO = (float)VIRTUAL_WIDTH/(float)VIRTUAL_HEIGHT;
	
	public static BitmapFont FONT;
	
	private OrthographicCamera camera;
	private Rectangle viewport;
	private SpriteBatch sb;

Like I said, when I run the desktop version it works fine but when I run it on my Galaxy S3, the game is zoomed out a lot, and it crops out the tops and sides of the game which is not what I want at all. If someone could help me that would be great. Thanks!

The method resize() is never called on Android.

You should draw your game in function of Gdx.getWidth() and Gdx.getHeight().

I work like that and that works perfectly but i’m not sure at all that’s the best method.

As BluePuppy said thats how i do it on android


camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());