【问题标题】:Layout Changes When I Run App On My Phone当我在手机上运行应用程序时布局发生变化
【发布时间】:2012-10-07 01:58:41
【问题描述】:

在我在 Eclipse 中的图形布局中,EditView、TextView 和按钮是我想要的位置。但是当我在手机上运行它们时,它们会被移动到不同的位置。有人可以帮我把它们放在我希望它们放在哪里吗?

这是我的代码:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/backgroundhdpi" >

        <EditText
            android:id="@+id/bill"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="100dp"
            android:ems="10"
            android:inputType="phone"
            android:text="Enter Your Bill"
            android:textSize="18dip" />

        <Button
            android:id="@+id/calculateTip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/bill"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="40dp"
            android:layout_marginLeft="15dp"
            android:text="Calculate" />

        <TextView
            android:id="@+id/tipOwed"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_above="@+id/bill"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="123dp"
            android:scrollHorizontally="false"
            android:text="Time to Tip!"
            android:textColor="#2c6f37"
            android:textSize="35dip"
            android:textStyle="bold" />

    </RelativeLayout>

【问题讨论】:

  • 您需要发布您的布局代码。此外,如果您在布局编辑器中使用不同的设备主题进行设计,如果您的手机具有不同的屏幕尺寸/密度,它在您的手机上看起来会有所不同。
  • 可能是您希望它的外观和实际外观的屏幕截图。
  • @user1657178 请同时添加截图。

标签: android android-layout button textview android-edittext


【解决方案1】:

如果我可能会问,您尝试运行您的代码的手机类型/单元是什么?从用户的角度来看,程序的布局有时取决于他们正在使用的手机屏幕。

例子:

您使用 Galaxy S2 模拟器运行应用程序,并尝试在 Galaxy Y 中运行它。由于两者屏幕分辨率的不同,您可以注意到布局可能占用的空间之间的差异。

另外,您是否将布局中使用的图像放在单个可绘制文件夹中?例如,drawable-hdpi? 将稍后将由您的布局使用的图像放置在不同的可绘制文件夹中可能会直接影响图像的大小或分辨率。

【讨论】:

  • 仅供参考,这可能应该是评论,而不是答案,因为您还没有真正解决任何问题:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-14
相关资源
最近更新 更多