I\'ve been playing around with Android development and one of the things I\'d like to be able to do is dynamically create a background image for my windows, similar to the one b
To accomplish this in my app, I had to find a View's dimensions within the main Activity. It looked something like this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gestureScanner = new GestureDetector(this); //Object for handling gestures.
mvView = new MyView(this); //MyView is class that extends View.
setContentView(myView);
}
@Override
public void onShowPress(MotionEvent e) {
//Returns the size of the entire window, including status bar and title.
DisplayMetrics dm = new DisplayMetrics();
this.getWindowManager().getDefaultDisplay().getMetrics(dm);
//Try to find the dimension of the view without the status/title bars.
int iViewHeight = mvMountain.getHeight();
int iViewWidth = mvMountain.getWidth();
Toast toast = Toast.makeText(this," View:" + iViewWidth + ","+iViewHeight + " Window: " + dm.widthPixels + " by " + dm.heightPixels, 2);
toast.show();
}