简体   繁体   English

如何在Android上处理不同尺寸的屏幕

[英]How to handle different sizes of screen on android

First, I run program on emulator. 首先,我在模拟器上运行程序。 After that, I run on many android phones. 之后,我在许多Android手机上运行。 Some are very small, some are show in rotate side then can't rotate back, and can't scroll (I did not do that), some are OK. 有些很小,有些显示在旋转侧,然后不能旋转回去,并且不能滚动(我没有这样做),有些还可以。

I understand may caused by different types of screen and I used AbsoluteLayout, but I do not know how to solve that problem.So, I need to resolve this problem. 我了解可能是由不同类型的屏幕引起的,因此我使用了AbsoluteLayout,但我不知道如何解决该问题,因此,我需要解决此问题。 Anyone can help? 有人可以帮忙吗? Thanks ka 谢谢ka

Example page that I did: 我做的示例页面:

  <?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
    android:id="@+id/usrname"
    android:layout_width="wrap_content"
    android:layout_height="21px"
    android:layout_x="105px"
    android:layout_y="179px"
    android:text="Username :"
    android:textSize="18sp"
    android:textStyle="bold" />

<EditText
    android:id="@+id/usrname_text"
    android:layout_width="161px"
    android:layout_height="wrap_content"
    android:layout_x="74px"
    android:layout_y="206px"
    android:textSize="12sp" />

<TextView
    android:id="@+id/pass"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="105px"
    android:layout_y="252px"
    android:text="Password :"
    android:textSize="18sp"
    android:textStyle="bold" >
</TextView>

<EditText
    android:id="@+id/pass_text"
    android:layout_width="163px"
    android:layout_height="wrap_content"
    android:layout_x="73px"
    android:layout_y="279px"
    android:password="true"
    android:textSize="12sp" />

<Button
    android:id="@+id/login"
    android:layout_width="73px"
    android:layout_height="wrap_content"
    android:layout_x="75px"
    android:layout_y="333px"
    android:text="Login" />

<Button
    android:id="@+id/cancle"
    android:layout_width="73px"
    android:layout_height="wrap_content"
    android:layout_x="157px"
    android:layout_y="333px"
    android:text="Cancel" />

</AbsoluteLayout>

These are pictures from Galaxy-S and emulator : 这些是来自Galaxy-S和模拟器的图片:

在此处输入图片说明在此处输入图片说明

对于这个问题,您可以在清单文件中使用“支持屏幕”标签。有关更多参考,请参见以下链接“ 支持屏幕”

The developer docs have lots of good guidance about this in the article on Supporting Multiple Screens . 支持多屏的文章中,开发人员文档对此有很多很好的指导。 Under the Best Practices section, they recommend not using AbsoluteLayout. 在“最佳做法”部分下,他们建议不要使用AbsoluteLayout。 If you share what you are trying to accomplish, we may be able to suggest a way that works on a wide range of screens. 如果您分享要完成的工作,我们可能会建议一种可在各种屏幕上使用的方法。

Really think you should look at relative layouts, esp if you are starting with android now. 真的认为您应该查看相对布局,尤其是如果您现在开始使用android。 Its a little harder, since you cant give absolute coordinates for any of your items, but you position your items with respect to one another. 因为您无法为任何项目提供绝对坐标,但是您将项目相对于彼此放置,这会有点困难。 After that you dont need to worry abt different screen sizes. 之后,您无需担心屏幕大小不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM