簡體   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