here is my code:
public class MainMenuActivity extends Activity implements OnClickListener {
public int width;
public int height;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenu);
Button play = (Button) findViewById(R.id.playbut);
Button credits = (Button) findViewById(R.id.creditsbut);
Button help = (Button) findViewById(R.id.helpbut);
play.setOnClickListener(this);
credits.setOnClickListener(this);
help.setOnClickListener(this);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
width = dm.widthPixels;
height = dm.heightPixels;
}
the problem is, public int width is not getting being set to dm.widthPixels and likewise for height. Any tips?
The code as given should result in the attributes being set. If it is not happening then there must be something else going on:
dmpixel attributes are not what you expect them to be.widthandheightvalues after the method call.If you are stumped, try running using a debugger, and setting a breakpoint in the method. Single step the method, and examine the actual values being set.