如何通过不同的屏幕缩放对象?

时间:2013-02-03 22:45:33

标签: android screen

我是Android新手,但我仍设法设计一款在我的智能手机上运行得很好的应用。我阅读了有关不同屏幕大小的Android支持的教程,我想:“好的,这很棒,Android本身会扩展应用程序以适应其他屏幕尺寸。我只需要为不同的分辨率设置不同的图像,这样它们就会看起来很棒更好。” 好吧,似乎我不明白它是如何工作的。通过在Android SDK中使用虚拟设备,我可以在较小的屏幕尺寸上运行我的应用程序。不幸的是,没有自动“缩放”,我的应用程序布局的一半没有显示在屏幕上。我的智能手机上的一个imageButton是屏幕的六分之一,它占据了这个新的小屏幕的三分之一。 我忘记了什么?我读了一些解释和其他帖子,但我得到的信息似乎表明自动缩放不会发生...也许我错过了一些基本规则? 谢谢

编辑: 下面我添加一些我的代码作为示例。即使屏幕尺寸发生变化,我应该如何更改它以使ImageButtons以相同的方式填充智能手机屏幕? (如果可能的话)。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@drawable/greenbackground"
 tools:context=".GameFrame" >

  <ImageButton
    android:id="@+id/image1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="30dp"
    android:layout_marginTop="27dp"
    android:background="@android:color/transparent"
    android:clickable="false"
    android:contentDescription="@string/app_name"
    android:src="@drawable/empty" />

  <ImageButton
    android:id="@+id/image2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/image1"
    android:layout_alignTop="@+id/image1"
    android:layout_marginLeft="16dp"
    android:background="@android:color/transparent"
    android:clickable="false"
    android:contentDescription="@string/app_name"
    android:src="@drawable/empty" />

<ImageButton
    android:id="@+id/image3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="14dp"
    android:layout_toRightOf="@+id/image2"
    android:layout_alignTop="@+id/image2"
    android:background="@android:color/transparent"
    android:clickable="false"
    android:contentDescription="@string/app_name"
    android:src="@drawable/empty" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

您需要使用ScollView才能显示在小屏幕上看不到的UI元素。请注意,ScrollView只能有一个孩子:

<ScollView
[...] >

  <MyParentLayout
   [...] >

      <MyUiElements
      [...] >

   </MyParentLayout>

</ScollView>