English 中文(简体)
Android 调整图像大小以匹配屏幕高度
原标题:Android- Re-size an image to match the screen s height

在我的应用程序中,对于相对布局的背景来说,我有一个非常大的网状壁纸(比任何手机/表格屏幕都大 ) 。 因此,我好奇的是,我不用用机器人来调整它,使它看起来可怕,我也可以自己调整它的规模。我想做的是调整图像的大小(垂直和水平,保持图像的正貌),直到图像S和屏幕的高度匹配。

感谢大家的帮助 感激不尽 Lijap

最佳回答

谷歌为此付出了巨大的努力。

基本上,你应该为每个目标大小/任务设置不同的大小。

这在Google Dev 支持多屏幕指南文件中有广泛的解释(大大超过我所能给出的解释) rel=“nofolth”>Google Dev 指南

从该页面上:

< 坚固 > screen 大小

Actual physical size, measured as the screen s diagonal. For simplicity, Android groups all actual screen sizes into four generalized sizes: small, normal, large, and extra large.

< 坚固> 硬度密度

屏幕物理区域内的像素数量; 通常称为 dpi( 每英寸点数) 。

For example, a "low" density screen has fewer pixels within a given physical area, compared to a "normal" or "high" density screen. For simplicity, Android groups all actual screen densities into four generalized densities: low, medium, high, and extra high.

<强 > 方向

从用户角度的屏幕方向。 这是景观或肖像, 意思是屏幕的纵横比是宽的或高的。 请注意, 不仅不同设备在默认情况下以不同方向运作, 而且在运行时当用户旋转设备时, 方向会改变 。

" 强 " 决议

屏幕上的物理像素总数。 在添加多屏幕支持时, 应用程序不会直接与分辨率发生作用; 应用程序应该只关注屏幕大小和密度, 如通用大小和密度组所指定 。

<强度 > 密度独立像素(dp)

A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way. The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application s UI, to ensure proper display of your UI on screens with different densities.

这样,您的用户将看到一个与其设备大小相匹配的位图。

如果您需要帮助理解该文件,或者该文件没有正确回答您的问题,请告诉我。

问题回答

Pheonixblade9 s 的回答是正确的, 但如果你重新决定重新定义自己, 那么你可以执行 < a href=" http:// developmenter.android.com/ reference/android/view/ View. html# sonSizeClanged% 28int,%20int,%20int,%20int,%20int%2029" rel=“nofollow” >Size Changed () 方法。 注意 on Sizechanged () 方法来自超级克拉斯( View) 。

如果图像太大(特别是如果图像大于任何分辨率),可能会发生OOM(内存)错误。

在这样的情况下,你必须保持记忆效率,谷歌已经发表了一些有关这个问题的教程。

见:http://developer.android.com/training/displaying-bittmaps/index.html





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签