计算的Andr​​oid屏幕尺寸 [英] Calculate screen size in android

查看:259
本文介绍了计算的Andr​​oid屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我走遍所有在互联网上寻找一种方式做一些事情,我认为将是非常基本的。底线是:我有我已经设计了一个Android UI。它由沿屏的中间放置的按钮。这是一个排序菜单画面。这些按钮需要在相同的位置,但应只增加或大小相减少到屏幕的物理尺寸。基本上,如果我有一个画面是1px的一个按钮(或浸;蘸是我目前在我的应用程序中使用)x 1px的,那么,如果我双屏幕大小,按钮应自动格式为2px点¯x2px的。我也做了数学上的我的应用程序。我有这个按钮是关于八百五十四分之二百二十五按住屏幕(这出来是从顶部约26.44%)。所有我想要做的就是让这个按钮下来相同的金额。说我的屏幕的大小减小到500,该比率应该保持相同。

I have traveled all over the internet looking for a way to do something that I thought would be very basic. Bottom line is: I have an android UI that I have designed. It consists of buttons that are placed along the middle of the screen. This is sort of a menu screen. These buttons need to be in the SAME location but should just increase or decrease in size in relation to the physical size of the screen. Basically, if i have a button on a screen that is 1px (or dip; dip is what i currently use in my application) X 1px, then, if i double the screen size, the button should auto-format to 2px X 2px. I have done the math on my application. The button that I have is about 225/854 down the screen (this comes out to be about 26.44% from the top.) All I want to do is make that button come down the same amount. Say I reduced the size of the screen to 500, the ratio should stay the same.

例如数学工作:

(225 DIP / 854像素)* 100 = 26.44%

(225 dip/854 px)*100=26.44%

所以,如果我减少屏幕大小为500像素,浸应该如下:

so if I reduce the screen size to 500px, the dip should be as follows.

(225dip / 854px)* 500像素= 131.733021077283372浸

(225dip/854px)*500px = 131.733021077283372 dip

这是去了解我的缩放按钮的最好方法?如果是这样,我怎么告诉我的应用程序来计算浸正确数量的该按钮应置于?

Is this the best way to go about scaling my buttons? If so, how do I tell my application to calculate the correct number of dip that the button should be placed at?

如果你仍然困惑(对不起!),这里是看这项工作的关键。

If you are still confused (sorry!), here is a key to looking at that work.

225dip =多远按钮从屏幕顶部归结。
屏幕854px =物理尺寸(像素)
131.733021077283372浸蘸=新的号码,如果屏幕缩小至500像素的物理尺寸

225dip = how far the button comes down from the top of the screen. 854px = physical size (in pixels) of the screen 131.733021077283372 dip = new number of dip if screen is reduced to 500px physical size

推荐答案

如果您使用的设计浸(或DP)和SP单位的接口(字体)可以让Android的做缩放你。虽然也许不是每个设备上像素完美,你的应用肯定会看起来一样在许多设备上以正确的比例。

If you design your interface using dip (or dp) and sp units (for fonts) you can let Android do the scaling for you. Although maybe not pixel perfect on every device, your app will certainly look the same on many devices in the correct scale.

支持多个屏幕上的中的http://ð .android.com相对=nofollow> http://d.android.com 介绍了此...

Supporting multiple screens on http://d.android.com describes this...

这篇关于计算的Andr​​oid屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆