android - 屏幕尺寸与按钮位置

标签 android xml android-layout

我正在尝试构建此应用程序,它在常规的 3.7 英寸 WVGA 屏幕上看起来很棒问题是,当您在更大的屏幕上安装该应用程序时,它看起来会消失。有想法该怎么解决这个吗?我想让按钮留在屏幕顶部的文本下方。 这是我的 XML。

<?xml version="1.0" encoding="utf-8"?>

<ScrollView android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout android:layout_width="fill_parent"
        android:orientation="vertical" android:layout_height="fill_parent" android:paddingLeft="60dip" android:paddingRight="60dip">


        <Button android:layout_height="wrap_content"
            android:layout_gravity="center" android:textColor="#ffd700"
            android:layout_marginBottom="2dip" android:id="@+id/ArButton01"
            android:background="@drawable/android_button" android:textSize="25dip"
            android:layout_width="fill_parent" />

        <Button android:layout_height="wrap_content"
            android:layout_gravity="center" android:background="@drawable/android_button"
            android:textColor="#ffd700" android:layout_marginBottom="2dip"
            android:id="@+id/ArButton02" android:textSize="25dip"
            android:layout_width="fill_parent" />

        <Button android:layout_height="wrap_content"
            android:layout_gravity="center" android:background="@drawable/android_button"
            android:textColor="#ffd700" android:layout_marginBottom="2dip"
            android:id="@+id/ArButton03" android:textSize="25dip"
            android:layout_width="fill_parent" />

        <Button android:layout_height="wrap_content"
            android:layout_gravity="center" android:background="@drawable/android_button"
            android:textColor="#ffd700" android:layout_marginBottom="2dip"
            android:id="@+id/ArButton04" android:textSize="25dip"
            android:layout_width="fill_parent" />

        <Button android:layout_height="wrap_content"
            android:layout_gravity="center" android:background="@drawable/android_button"
            android:textColor="#ffd700" android:layout_marginBottom="2dip"
            android:id="@+id/ArButton05" android:textSize="25dip"
            android:layout_width="fill_parent" />

        <Button android:layout_height="wrap_content"
            android:layout_gravity="center" android:background="@drawable/android_button"
            android:textColor="#ffd700" android:layout_marginBottom="2dip"
            android:id="@+id/ArButton06" android:textSize="25dip"
            android:layout_width="fill_parent" />

        <Button android:layout_height="wrap_content"
            android:layout_gravity="center" android:background="@drawable/android_button"
            android:textColor="#ffd700" android:layout_marginBottom="2dip"
            android:id="@+id/ArButton07" android:textSize="25dip"
            android:layout_width="fill_parent" />

        <Button android:layout_height="wrap_content"
            android:layout_gravity="center" android:background="@drawable/android_button"
            android:textColor="#ffd700" android:layout_marginBottom="2dip"
            android:id="@+id/ArButton08" android:textSize="25dip"
            android:layout_width="fill_parent" />

        <Button android:layout_height="wrap_content"
            android:layout_gravity="center" android:background="@drawable/android_button"
            android:textColor="#ffd700" android:layout_marginBottom="2dip"
            android:id="@+id/ArButton09" android:textSize="25dip"
            android:layout_width="fill_parent" />

        <Button android:layout_height="wrap_content"
            android:layout_gravity="center" android:textStyle="bold"
            android:background="@drawable/android_button" android:textColor="#ffd700"
            android:layout_marginBottom="2dip" android:id="@+id/ArButton10"
            android:textSize="25dip" android:layout_width="fill_parent" />

        <!-- <Button android:layout_height="wrap_content" -->
        <!-- android:layout_width="200dip" android:layout_gravity="center" -->
        <!-- android:textStyle="bold" android:background="@drawable/android_button" -->
        <!-- android:textColor="#ffd700" android:layout_marginBottom="2dip" -->
        <!-- android:id="@+id/ArButton11" android:textSize="25dip" /> -->

    </LinearLayout>
</ScrollView>

3.7 WVGA (N1 size

enter image description here

感谢您的关注。

最佳答案

您需要为不同的设备/屏幕提供不同的 XML 布局。对于 Gingerbread (Android 2.3),总共支持 8 种不同的屏幕尺寸。您可以通过在 res 文件夹中创建多个布局文件夹来做到这一点。

将您当前的布局文件夹重命名为“layout-normal-hdpi”(对于普通尺寸屏幕上的 WVGA800)。创建一个新文件夹“layout-large-mdpi”(用于大屏幕上的 WVGA800)。这两个文件夹都适用于具有 WVGA800 分辨率但屏幕物理尺寸不同的设备。

将您的布局 XML 文件从“layout-normal-hdpi”复制到“layout-large-mdpi”并更改按钮位置,以便它在具有更大屏幕的设备上看起来像您希望的样子屏幕。 Android 会根据设备的硬件自动选择正确的布局。

请注意,这 2 个 XML 文件的名称应该完全相同,只是它们所在文件夹的名称应该不同。

有关支持的其他屏幕尺寸和分辨率的更多信息,请查看 http://developer.android.com/guide/practices/screens_support.html .

关于android - 屏幕尺寸与按钮位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5131939/

相关文章:

android - webview 是否像 videoview 一样创建一个单独的表面?

php - 使用 PHP simplexml_load_string 解析 xml

android - TextView 不显示。但是在 logcat 中显示时一切正常

android - 在不使用完全限定类名的情况下使用 XML 中的自定义 View

android - float 操作按钮转换问题

java - 我找不到教程中显示的 android.jks 文件

java - Android:获取本地日期格式,因为它是带有字母而不是数字的字符串

java - Android 版本低于 2.2 的 org.w3c.dom.Node

c# - 我可以从我将要读取的 xml 文件创建一个 XmlNamespaceManager 对象吗?

java - Android Studio - 应用程序不包括模拟器