开发者

Getting screen height before first display?

I have a ListView. I populate it with 8 items, that's all that fits vertically on the G1. Some of my users are saying the Droid has a taller screen height, and so I can probably add one or two more items to the ListView to take up the additional space provided.

How could I measure the available height the screen offers at startup, before the UI is displayed? If I see the height can fi开发者_运维问答t more than 8 items, I'd like to add one or two more rows.


I agree to the comments made above, but if you really want to go down that road, try this:

Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

You can do that from your main activity, the one that's started from the launcher.

However, this does not take into account the space taken by the notification bar or window decorations, so in reality, you have less space than width times height.


Here is the code I use the most:

public class MainActivity extends Activity {

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.????????);

    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    Constants.SCREEN_HEIGHT = dm.heightPixels;
    Constants.SCREEN_WIDTH = dm.widthPixels;
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜