【问题标题】:Set minimum size of the Nine-Patch设置九补丁的最小尺寸
【发布时间】:2011-12-06 14:35:38
【问题描述】:

我想将九块可绘制对象作为视图的背景。当视图大小小于我指定的最小值时,我希望它缩小。另一方面,当视图的大小大于指定的大小时,我希望这个九补丁可绘制对象像往常一样增长。这是所需的可绘制行为的说明:

是否真的有可能使用九补丁可绘制对象来实现这一点?

【问题讨论】:

    标签: android drawable scale nine-patch


    【解决方案1】:

    我不确定您是否正确使用了九个补丁,我宁愿使用带有九个补丁的 ImageButton 作为背景,中间没有星星。然后,您可以使用 ImageButton 上的 android:scaleType 属性来根据需要缩放图像。

    这是一个示例(使用单独的可绘制对象在按钮上显示您的星号):

     <ImageButton
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:src="@drawable/star"
         android:background="@drawable/nine_patch"
         android:adjustViewBounds="true"
         android:scaleType="fitXY"
         android:layout_weight="1" />
    

    【讨论】:

    • 问题是我想为任何视图设置背景,不限于 ImageButton。
    • 这在 XML 中是不可能的。但是,您可以创建自定义视图并根据需要绘制背景。
    猜你喜欢
    • 2012-05-10
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    相关资源
    最近更新 更多