通过不同屏幕进行对象缩放的工作原理



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

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

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

您需要使用ScollView才能显示小屏幕上不可见的 UI 元素。请记住,一个ScrollView只能有一个孩子:

<ScollView
[...] >
  <MyParentLayout
   [...] >
      <MyUiElements
      [...] >
   </MyParentLayout>
</ScollView>

最新更新