android - 图像根据宽度和高度在图像按钮中拉伸(stretch)

标签 android android-layout

这个 ImageButton 是可点击的。我需要在没有拉伸(stretch)的情况下在中心显示这个图标。有没有办法添加宽度和高度或属性?请给我一个主意。谢谢

<ImageButton
    android:layout_width="60dp"
    android:layout_height="wrap_content"
    android:background="@drawable/usercalltab"/>

用户调用表.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
            <item>
                <shape android:shape="rectangle" >
                    <solid android:color="#ffdbab" />
                </shape>
            </item>
            <item>
                 <bitmap android:src="@drawable/search"/>
            </item>
        </layer-list>
    </item>
    <item>
        <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
            <item>
                 <bitmap android:src="@drawable/callme"/>
            </item>
        </layer-list>
        </item>
</selector>

enter image description here

最佳答案

像这样尝试:

<ImageButton
android:layout_width="60dp"
android:layout_height="wrap_content"
android:src="@drawable/usercalltab"
android:scaleType="centerInside"
/>

或者android:scaleType="center"

我认为其中一个应该是您正在寻找的

关于android - 图像根据宽度和高度在图像按钮中拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15973486/

相关文章:

Android 4.1 change - transition 和 webkittransition defiend,如何正确确定 transition end event 的名称?

android - 缩放已定义相对尺寸的简单 UI

android - android listView 行向左或向右对齐

android - 如何为动态创建的 View 设置 OnTouchListener?

android - 广播接收器最高优先级不工作

android - 在android中填充编辑文本的语音输入?

java - 坚持使用 Dagger 进行 Activity 的演示者

android - 即使在 layout_height 上使用 WRAP_CONTENT,RecycleView 也会显示间隙之间的额外空间

android - ViewPager 终止后 fragment 布局不显示

android - 触摸图像时,全屏 ImageView 和缩放应该可以工作