简体   繁体   中英

How to handle different sizes of screen on android

First, I run program on emulator. After that, I run on many android phones. 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. Anyone can help? Thanks 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 :

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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