【问题标题】:Android image scaling Layout issueAndroid图像缩放布局问题
【发布时间】:2012-03-10 23:03:35
【问题描述】:

我正在尝试设计一个应用程序,需要创建一个非常简单的菜单栏,其中包含一个图像按钮我为所有分辨率的按钮创建了图像,并为所有不同的分辨率创建了相同高度的图像栏,但问题是必须坐在普通图像顶部的图像按钮总是更高,我不知道为什么,例如在 hdpi 下我有菜单栏图像 1024x72 和按钮 72x72 的另一个图像但是当渲染图像按钮时总是大我要疯了,试图找到答案,任何帮助将不胜感激。

这是我当前不工作的代码

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    android:id="@+id/layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_menu_menu_bar"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true" />






<ImageButton
    android:id="@+id/new_convo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageView1"
    android:layout_alignParentTop="true"
    android:src="@drawable/ic_menu_new_convo" />

</RelativeLayout>

【问题讨论】:

  • 为什么不指定高度为72dp
  • 但是它总是被设置为我认为拥有 hdpi mdpi 和 ldpi 的目的是让它为当前设备选择最好的
  • 是的。但是dp 是与密度无关的像素,无论屏幕密度如何,都会在设备上缩放以匹配所需的尺寸。
  • 是的,使用 dp 或 dip,它与密度无关。

标签: java android layout imagebutton


【解决方案1】:

对于菜单栏,LinearLayout 是最佳选择。您必须为背景指定渐变或 9 色块,然后使用您的 ImageButtons。在 Android 上并不能保证窗口宽度为 1024px,因此您必须改变思维方式,以不同于其他移动平台的方式处理 UI 设计。如果您提供了预期结果的草图,我们可以更好地理解(和帮助)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多