Everything I've read says you can't call getWidth()
or getHeight()
on a View
in a constructor, but I'm calling them in onResume()
. Shouldn't the screen's layout have been drawn by then?
@Override
protected void onResume() {
super.onResume();
populateData();
}
private void populateData() {
LinearLayout test = (LinearLayout) findViewById(R.id.myview);
double widthpx = test.getWidth();
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…