0

我已经为 android 编写了一个应用程序,我希望它可以在不同屏幕尺寸的手机上工作。这是我的 main.xml 代码:

 <?xmlversion="1.0"encoding="utf-8"?>
  <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">

 <AbsoluteLayout
 android:id="@+id/absoluteLayout1"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_weight="1.11"
 android:background="@color/dRed">

<Button
 android:id="@+id/Button02"
android:layout_width="285dp"
android:layout_height="76dp"
android:layout_x="122dp"
android:layout_y="340dp"
android:background="@drawable/border"
android:text="Exit"
android:textColorHighlight="@color/white"
android:textSize="30dip"/>

<Button
android:id="@+id/Button01"
android:layout_width="285dp"
android:layout_height="76dp"
android:layout_x="122dp"
android:layout_y="250dp"
android:background="@drawable/border"
android:text="About!"
android:textColorHighlight="@color/white"
 android:textSize="30dip"/>

 <Button
 android:id="@+id/button1"
 android:layout_width="285dp"
 android:layout_height="76dp"
 android:layout_x="122dp"
 android:layout_y="159dp"
 android:background="@drawable/border"
 android:text="Play Game!"
 android:textColorHighlight="@color/white"
 android:textSize="30dip"/>

   <TextView
  android:id="@+id/textView1"
   android:layout_width="333dp"
   android:layout_height="93dp"
   android:layout_x="105dp"
   android:layout_y="26dp"
   android:text="Smily XO  !!!"
   android:textAppearance="?android:attr/textAppearanceLarge"
   android:textColor="@color/orange"
   android:textColorHighlight="@color/white"
   android:textSize="60dip"/>

 <ImageView
  android:id="@+id/imageView1"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_x="291dp"
  android:layout_y="26dp"
  android:src="@drawable/nice"/>

   </AbsoluteLayout>

  </LinearLayout>

它非常适合模拟器,但不适合手机屏幕。android中是否有任何命令可以使其自动适应不同的手机?在此链接 Androidmanifest.xml 我的 Android 应用程序并没有真正填满屏幕 我发现我应该添加以下代码,但我不确定在哪里编写此代码

android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"/>
4

3 回答 3

0

首先不要使用绝对布局,因为它已被弃用。您可以根据您的选择/需要使用线性/相对布局。然后,为了让所有屏幕分辨率的外观和感觉均匀,你必须看看这个支持多屏幕的 android

您可以添加不同的布局文件夹,如layout-largelayout-xlarge等,并将您的 xml 相应地放入这些文件夹中。此外,使用 wrap-content、match-parent 比使用硬编码的高度和宽度更受欢迎。否则,您可能必须为位于不同布局文件夹中的每个 xml 文件更改特定视图的高度/宽度。

于 2013-09-11T14:02:00.920 回答
0

在 Manifest 文件中,在应用程序标签上方使用以下代码,

<supports-screens
        android:anyDensity="true"
        android:largeScreens="true"
        android:normalScreens="true"
        android:smallScreens="true"
        android:xlargeScreens="true" />

then<AbsoluteLayout/>完全被 android API 弃用,

在小屏幕上使用layout文件夹,resources

layout-land为横向创建文件夹,

如果是平板电脑和大屏幕-->layout-large-hdpi在资源中创建文件夹,

将所有 layout.xml 文件复制到创建的文件夹中,它将自动调整,,

于 2013-09-11T14:24:29.133 回答
0

AbsoluteLayout 已弃用,强烈建议不要使用。您应该改为使用 RelativeLayout或其他有效布局。绝对布局没有为不同的屏幕尺寸和密度做出规定,因此不能很好地自动适应不同的设备。

如果您希望线性布局的子视图在所有屏幕尺寸上占据某些权重或比例,您还可以查看布局权重:layout_weightweightSum

于 2013-09-11T13:34:57.843 回答