【问题标题】:Android ImageButton LayoutAndroid ImageButton 布局
【发布时间】:2014-03-03 13:13:20
【问题描述】:

大家好,我想在 android 中创建一个图像按钮,但我想为该图像按钮导入的图像不适合按钮布局。任何人都知道我怎样才能使图像适合按钮的宽度和高度?所以基本上按钮的宽度和高度会缩放我的图像宽度和比例。非常感谢提前。!

我的代码:(来自评论)

<ImageButton 
   android:id="@+id/imageButton1"
   android:layout_width="wrap_content" 
   android:layout_height="wrap_content" 
   android:layout_alignParentRight="true" 
   android:layout_alignParentTop="true" 
   android:src="@drawable/imagebtn2" 
   android:scaleType="fitXY"/>

【问题讨论】:

  • 用相关代码显示你的xml文件
  • 你可以使用android:scaleType="fitXY"
  • fitxy 不起作用,我的 xml 文件是相对布局,图像按钮代码如下所示:
  • 'code'
  • 测试其他scaleType,看看什么最适合你

标签: android xml layout imagebutton


【解决方案1】:

您必须在 ImageButton 上使用不同的 scaleType

请参阅此处以获取可能的ScaleTypes 列表:http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

您可以像这样在 xml 中设置ScaleType

<ImageButton
 ....
 android:scaleType="center"
 ....

【讨论】:

  • 嘿,感谢您的帮助,但我正在尝试更改 scaleType,但它不会更改为 android 给我的任何选项。
【解决方案2】:

如果你想把图片作为按钮,那么你必须调整你打算作为按钮的图片的大小。

android 支持不同类型的布局,例如 hdpi、ldpi、mdpi、xhdpi 和 xxhdpi,其中屏幕的分辨率会相应改变。

[这里是调整图片大小的链接HERE

保存不同大小的图像后,它应该放在受尊重项目的受尊重的可绘制文件夹中。

【讨论】:

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