【问题标题】:keep button drawable image dimensions as original保持按钮可绘制图像尺寸为原始尺寸
【发布时间】:2020-11-19 19:18:45
【问题描述】:

我创建了一个应用,在其中使用了 Google Books API。

作为他们需要的属性的一部分,我需要在每个查询结果中添加以下button

现在,我想将该图像用作按钮的背景,但结果如下:

如您所见,它似乎被拉长了,质量很差。

我使用的xml是:

<ImageButton
    android:id="@+id/tv_Link"
    android:layout_width="wrap_content"
    android:layout_height="24dp"
    android:layout_alignStart="@+id/imagecard"
    android:layout_alignEnd="@+id/imagecard"
    android:layout_alignBottom="@+id/imagecard"
    android:background="@drawable/gbs_preview_button"
    android:elevation="50dp"
    android:fontFamily="@font/assistant_semibold"
    android:gravity="center"
    android:textColor="@color/colorLightPurple"
    android:textSize="8sp" />

为了修复它,我决定使用位图:

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:gravity="center"
    android:src="@drawable/gbs_preview_button"
    android:tileMode="disabled"/>

问题是它变得像这样小(质量很好,但很小):

此尺寸太小,因为它们要求高度为 24dp。

有什么方法可以将此图像添加到按钮,使其高度为 24dp 并仍然保持图像质量?

谢谢

【问题讨论】:

    标签: android xml android-drawable android-imagebutton google-books


    【解决方案1】:

    由于您要将高度硬编码为24dp,因此您也可以将宽度硬编码为一个值,以保持原始图像尺寸的纵横比为 (88 x 31)。

    因此,将宽度设置为 68dp 而不是 wrap_content

    【讨论】:

    • 我似乎仍然降低了图像的质量,但我想它与之前相比仍然更好。
    • 如果你能得到比这更高质量的图像,那就更好了
    • 我能找到的只是他们官方链接到这张图片的链接,正如你所说的那样,它是 88x31。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-04
    • 2013-04-17
    • 2019-02-02
    • 2020-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多