【问题标题】:how to create android UI so that it does not change with screen resolution?如何创建android UI,使其不随屏幕分辨率而改变?
【发布时间】:2012-07-23 12:36:27
【问题描述】:

我有一个带有背景图像的 android 应用程序,我将在模拟器上部署它并查看它的行为。

最初我使用的是皮肤为 WVGA800 的模拟器。在 UI 中,布局中声明的所有 textView 都已正确放置。 但是当我将模拟器皮肤更改为 500x600 时,UI 中的一些 textView 会错位。

那么任何人都可以建议如何处理这个问题。

【问题讨论】:

  • 你能把你的代码贴在这里吗??
  • 总是需要布局代码:)
  • “损坏”和“工作”布局的屏幕截图也是一个好主意。
  • 我真的不明白 500x600 模拟器的意义,因为没有 Android 设备具有该分辨率。也许您可以模仿一些实际设备并确保您的 UI 看起来不错?
  • 你经历过这个吗? developer.android.com/guide/practices/screens_support.html 惊人的文档。

标签: android android-layout android-emulator


【解决方案1】:

我的选择: 1)对于简单的用户界面,我认为你可以使用许多带有视图的attars,如下; android:layout_centerHrizontal android:layout_centerVertical
android:layout_centerInparent
机器人:layout_alignParentBottom android:layout_alignParentLeft
android:layout_alignParentRight
android:layout_alignParentTop
android:layout_alignWithParentIfMissing

android:layout_below
android:layout_above
android:layout_toLeftOf
android:layout_toRightOf
android:layout_alignTop
安卓:layout_alignLeft
机器人:layout_alignBottom android:layout_alignRight

android:layout_marginBottom
android:layout_marginLeft
android:layout_marginRight
android:layout_marginTop

这有助于使用布局或视图属性来设置其位置。 2)你可以使用一些布局xml来适应它。就像那样

if(screen width < 480)
setcontentview(r.layout.for480lay)
else if(screen width > 480&&screen width <640)
setcontentview(r.layout.for640lay)
..
..

【讨论】:

    【解决方案2】:

    Android 的优点是,但您不知道运行代码的设备的大小或纵横比是多少。如果您想要全屏图像,您需要愿意对它们进行缩放(按比例或不成比例)或裁剪。

    如果您试图将文本放置在背景图像上的特定位置,您将遇到麻烦。我以前试过这个,很快就改变了主意。

    这是我的建议:阅读屏幕支持 docs(正如 @abhilasha 所说)并使用可很好缩放的自适应 UI 元素(如 9-patch 图像、相对布局等)。

    然后,如果您想在图像中放置文本,而不是尝试将TextView 放在ImageView 上,请将您想要的图像设置为TextView 的背景。然后你就知道文本相对于图像的位置了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-08
      • 2015-04-06
      • 1970-01-01
      • 2012-03-04
      相关资源
      最近更新 更多