【问题标题】:How to resize Image to button?如何将图像大小调整为按钮?
【发布时间】:2016-09-17 03:13:06
【问题描述】:

所以我有一个ImageButton,但图像非常适合它。我尝试了android:scaleType="center",但它失败了,因为图像居中但它太小了,尝试了fitXY,但结果相同。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f1e8e8"
    tools:context="com.example.bassam.myapplication123.MainActivity">
    <ImageButton android:id="@+id/myButton"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:padding="100dip"
        android:background="#ffffff"
        android:src="@drawable/Work"
        android:scaleType="fitXY"
        ></ImageButton>
</RelativeLayout>

【问题讨论】:

  • 可以分享一下你想要实现的截图吗
  • 把drawable放到后台android:background="@drawable/Work"
  • @DkgMarine 也分享你想要实现的图片
  • @SecretCoder 我正在尝试别的东西,但忘了删除它大声笑

标签: android image android-studio


【解决方案1】:

如果我理解你的担忧是正确的,你只是想让图像缩放到ImageButton 本身的大小,只需使用

android:scaleType="fitCenter"

图像会根据ImageButton 的大小进行调整。试试看,让我知道它是否有效。干杯! :)

【讨论】:

  • 我注意到你有一个background 元素和一个src 元素。是否有理由需要分离元素?如果您的目标是用图像覆盖 ImageButton,为什么不使用图像本身设置 background。我在最后尝试了 background 设置为您想要的图像。
  • 不用担心。干杯! :D
猜你喜欢
  • 2011-07-04
  • 2022-12-09
  • 1970-01-01
  • 2023-03-29
  • 2014-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多