Получить ширину и высоту экрана в Android - PullRequest
397 голосов
/ 20 января 2011

Как узнать ширину и высоту экрана и использовать это значение в:

@Override protected void onMeasure(int widthSpecId, int heightSpecId) {
    Log.e(TAG, "onMeasure" + widthSpecId);
    setMeasuredDimension(SCREEN_WIDTH, SCREEN_HEIGHT - 
        game.findViewById(R.id.flag).getHeight());
}

Ответы [ 22 ]

0 голосов
/ 05 февраля 2018

Я нашел weigan лучший ответ на этой странице, вот как вы можете использовать его в Xamarin.Android:

public int GetScreenWidth()
{
    return Resources.System.DisplayMetrics.WidthPixels;
}

public int GetScreenHeight()
{
    return Resources.System.DisplayMetrics.HeightPixels;
}
0 голосов
/ 21 сентября 2017
       @Override
        protected void onPostExecute(Drawable result) {
            Log.d("width",""+result.getIntrinsicWidth());
            urlDrawable.setBounds(0, 0, 0+result.getIntrinsicWidth(), 600);

            // change the reference of the current drawable to the result
            // from the HTTP call
            urlDrawable.drawable = result;

            // redraw the image by invalidating the container
            URLImageParser.this.container.invalidate();

            // For ICS
            URLImageParser.this.container.setHeight((400+URLImageParser.this.container.getHeight()
                    + result.getIntrinsicHeight()));

            // Pre ICS`enter code here`
            URLImageParser.this.container.setEllipsize(null);
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...