繁体   English   中英

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

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

首先,我在模拟器上运行程序。 之后,我在许多Android手机上运行。 有些很小,有些显示在旋转侧,然后不能旋转回去,并且不能滚动(我没有这样做),有些还可以。

我了解可能是由不同类型的屏幕引起的,因此我使用了AbsoluteLayout,但我不知道如何解决该问题,因此,我需要解决此问题。 有人可以帮忙吗? 谢谢ka

我做的示例页面:

  <?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>

这些是来自Galaxy-S和模拟器的图片:

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

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

支持多屏的文章中,开发人员文档对此有很多很好的指导。 在“最佳做法”部分下,他们建议不要使用AbsoluteLayout。 如果您分享要完成的工作,我们可能会建议一种可在各种屏幕上使用的方法。

真的认为您应该查看相对布局,尤其是如果您现在开始使用android。 因为您无法为任何项目提供绝对坐标,但是您将项目相对于彼此放置,这会有点困难。 之后,您无需担心屏幕大小不同。

暂无
暂无

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

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