ImageButton: Mipmap source image not stretching to fill button

Charlieabee

I have an ImageButton that is the child to a RelativeLayout that uses a mipmap resource for it's source. However I'm having an issue with the mipmap stretching to fill the ImageButton.

In all of the threads I've read people have recommended "android:scaleType="fitXY"" yet this does not seem to work for me. The XML is listed below.

<RelativeLayout
    android:layout_width="330dp"
    android:layout_height="50dp"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="30dp">

    <EditText
        android:id="@+id/search_edit_text"
        android:layout_width="280dp"
        android:layout_height="50dp"
        android:hint="@string/search_hint"
        android:background="#EAEAEA"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:layout_margin="0dp"
        android:textColorHint="#C9C9C9"/>

    <ImageButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_toRightOf="@id/search_edit_text"
        android:layout_margin="0dp"
        android:scaleType="fitXY"
        android:padding="0dp"
        android:stateListAnimator="@null"
        android:src="@mipmap/search_button_icon"
        android:background="@null"/>

</RelativeLayout>

The image below is the result of the above XML, however the search button (to the right of the edittext element) should be the same height, and be attached to the edittext.

search bar

Any help is appreciated.

mawalker

I just copy/pasted your code, and the image below is what I get (I used default android:src="@mipmap/ic_launcher")

And I get a visual similar to yours.

enter image description here

Where it looks like the image isn't "stretching"

enter image description here

However if you click on the image you see that image's boarder perfect matches the EditText to its Left.

So my guess is that your input Image 'search_button_icon' Has built in padding in the Image itself and would need to be cropped if you want it to be 'exact' visually as the EditText.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

ImageButton:Mipmap源图像未拉伸到填充按钮

来自分类Dev

ImageView与ImageButton与Button

来自分类Dev

Button和ImageButton的外观差异

来自分类Dev

以编程方式按比例缩小Image的ImageButton

来自分类Dev

图片未显示在Image和ImageButton中

来自分类Dev

图片未显示在Image和ImageButton中

来自分类Dev

如何动态设置ImageButton上的Image?

来自分类Dev

fit / fill image?

来自分类Dev

如何在“代码隐藏”中检查XAML上定义的Button中的Image Source?

来自分类Dev

Android Mipmap?

来自分类Dev

Android Mipmap?

来自分类Dev

Fill a portion of drawn image in canvas

来自分类Dev

Fill a rectangle with a larger image with Cairo

来自分类Dev

mipmap纹理显示错误

来自分类Dev

使用什么mipmap或drawable

来自分类Dev

OpenGL Cubemap:写入mipmap

来自分类Dev

mipmap纹理显示错误

来自分类Dev

OpenGL Cubemap:写入mipmap

来自分类Dev

如何在 Java/Android Studio 中在 ClickOut 上使 Imagebutton 更改 Image onClick in 并返回到原始图像

来自分类Dev

无效的选择器 webkit-credentials-auto-fill-button

来自分类Dev

渲染到纹理的mipmap级别

来自分类Dev

使用SharpDX的Directx 11.2 Mipmap?

来自分类Dev

渲染到纹理的mipmap级别

来自分类Dev

在Metal中访问Mipmap级别

来自分类Dev

读取特定密度的Mipmap资源

来自分类Dev

手动生成 mipmap

来自分类Dev

渲染到纹理 mipmap 级别

来自分类Dev

How to get Image.Source as string

来自分类Dev

ObjectDisposedException when I try to use an Image source