【问题标题】:Using imageButton on an Android Layout在 Android 布局上使用 imageButton
【发布时间】:2014-01-13 16:54:10
【问题描述】:

我想将图像用作 Android 应用程序的按钮,因此我使用的是 ImageButton。 我希望它很大,所以我明白最好的方法是将图像的背景配置为我想要的图像。 我将布局宽度和高度设置为 250dip,但分辨率很低。 图像是 1000X1000 像素,所以没有真正的理由会显示像素化,因为它正在显示...... 有没有办法解决这个问题?要将图像按钮设置得非常大并使用质量更好的图像(例如来自 drawable-xhdpi)? 谢谢!

编辑:

这是 imageView 的代码:

<ImageView
    android:id="@+id/activateButtonImage"
    android:layout_width="250dip"
    android:layout_height="250dip"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:contentDescription="@null"
    android:minHeight="250dip"
    android:minWidth="250dip"
    android:scaleType="centerInside"
    android:background="@drawable/deactivateicon"
    />

截图:

【问题讨论】:

  • 两个答案都正确,我的问题是将图片导入项目 usibg eclipse。它奇怪地缩放它们并使用低分辨率属性。解决方案只是将 insge 复制到项目文件夹中。谢谢!

标签: android image button imagebutton dpi


【解决方案1】:

你的图片很大。尝试添加:

android:scaleType="centerInside" 到 xml 布局文件中的 ImageButton

【讨论】:

  • 试过了..也没有用
【解决方案2】:

您还可以使用带有onClick 的 ImageView 来充当按钮。如果图像是资源,请在 android:src=@drawable/image 参数中引用它并按照 Gabe 的回答建议对其进行缩放。

【讨论】:

  • 我正在尝试您所说的内容,包括@Gabe 的回答,但符号现在看起来很小..(它没有变大)这就是我写的:
  • 如果图像是 1000x1000 并且您的视图是 250dp x 250dp,则它不应该太小。可以发截图吗?
  • 我不确定为什么您的图像会按您提到的尺寸放大。使用 scaleType、padding 或视图宽度和高度。确保您使用 android:src 而不是 android:background 引用可绘制对象
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多