Last active
August 29, 2015 14:22
-
-
Save mstfldmr/eeb2a4d3d8ccec5d77fe to your computer and use it in GitHub Desktop.
Get Display Size in Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.aldemir.myapp.camera; | |
import android.content.Context; | |
import android.content.res.Configuration; | |
import android.graphics.Point; | |
import android.hardware.Camera; | |
import android.os.Handler; | |
import android.util.AttributeSet; | |
import android.util.Log; | |
import android.view.Display; | |
import android.view.Surface; | |
import android.view.SurfaceHolder; | |
import android.view.SurfaceView; | |
import android.view.ViewGroup; | |
import android.view.WindowManager; | |
import java.util.List; | |
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback { | |
public int getDisplaySize() { | |
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); | |
Display display = wm.getDefaultDisplay(); | |
Point size = new Point(); | |
display.getSize(size); | |
int width = size.x; | |
int height = size.y; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.aldemir.myapp.gui.activity; | |
import android.graphics.Point; | |
import android.os.Bundle; | |
import android.view.Display; | |
import at.ingdiba.ingdibaapp.R; | |
import at.ingdiba.ingdibaapp.gui.activity.base.BaseActionBarActivity; | |
public class MyActivity extends BaseActionBarActivity { | |
@Override | |
public void onCreate(Bundle state) { | |
super.onCreate(state); | |
setContentView(R.layout.activity_barcode_reader); | |
Display display = getWindowManager().getDefaultDisplay(); | |
Point size = new Point(); | |
display.getSize(size); | |
int width = size.x; | |
int height = size.y; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment