`
jguangyou
  • 浏览: 375741 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Drawable资源之ScaleDrawable资源

 
阅读更多

A drawable defined in XML that changes the size of another drawable based on its current level.

file location:
res/drawable/filename.xml
The filename is used as the resource ID.
compiled resource datatype:
Resource pointer to a ScaleDrawable.
resource reference:
In Java: R.drawable.filename
In XML: @[package:]drawable/filename
syntax:
<?xml version="1.0" encoding="utf-8"?>
<scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/drawable_resource"
    android:scaleGravity=["top" | "bottom" | "left" | "right" | "center_vertical" |
                          "fill_vertical" | "center_horizontal" | "fill_horizontal" |
                          "center" | "fill" | "clip_vertical" | "clip_horizontal"]
    android:scaleHeight="percentage"
    android:scaleWidth="percentage" />
 
elements:
<scale>
Defines the scale drawable. This must be the root element.

attributes:

xmlns:android
String. Required. Defines the XML namespace, which must be"http://schemas.android.com/apk/res/android".
android:drawable
Drawable resource. Required. Reference to a drawable resource.
android:scaleGravity
Keyword. Specifies the gravity position after scaling.

Must be one or more (separated by '|') of the following constant values:

Value Description
top Put the object at the top of its container, not changing its size.
bottom Put the object at the bottom of its container, not changing its size.
left Put the object at the left edge of its container, not changing its size. This is the default.
right Put the object at the right edge of its container, not changing its size.
center_vertical Place object in the vertical center of its container, not changing its size.
fill_vertical Grow the vertical size of the object if needed so it completely fills its container.
center_horizontal Place object in the horizontal center of its container, not changing its size.
fill_horizontal Grow the horizontal size of the object if needed so it completely fills its container.
center Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
fill Grow the horizontal and vertical size of the object if needed so it completely fills its container.
clip_vertical Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip is based on the vertical gravity: a top gravity clips the bottom edge, a bottom gravity clips the top edge, and neither clips both edges.
clip_horizontal Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip is based on the horizontal gravity: a left gravity clips the right edge, a right gravity clips the left edge, and neither clips both edges.
android:scaleHeight
Percentage. The scale height, expressed as a percentage of the drawable's bound. The value's format is XX%. For instance: 100%, 12.5%, etc.
android:scaleWidth
Percentage. The scale width, expressed as a percentage of the drawable's bound. The value's format is XX%. For instance: 100%, 12.5%, etc.
example:
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/logo"
    android:scaleGravity="center_vertical|center_horizontal"
    android:scaleHeight="80%"
    android:scaleWidth="80%" />
 
分享到:
评论

相关推荐

    Android中Drawable分类汇总

    - ScaleDrawable:用于缩放其他Drawable资源的Drawable。 - StateListDrawable:可以包含多种状态(如选中、按下等),根据不同的状态显示不同的Drawable。 - TransitionDrawable:用于在两个Drawable资源之间创建...

    android安卓APP之13种Drawable位图片资源.zip_android客户端是什么

    本资源包“android安卓APP之13种Drawable位图片资源.zip”涵盖了Android开发中常见的13种Drawable类型,这些类型极大地丰富了Android应用的视觉表现和动态效果。下面将详细介绍每种Drawable的特性和用法。 1. **...

    android drawable下的xml详解

    **ColorDrawable**是最简单的`drawable`类型之一,它用于表示一个单一颜色的绘制区域。在XML布局文件中,可以通过`&lt;color&gt;`标签来定义一个颜色资源,并通过`android:color`属性指定具体的颜色值。例如,以下XML代码...

    android Drawable分类汇总

    7. **`ScaleDrawable`**:用于创建可以按比例缩放的 `Drawable`。 8. **`RotateDrawable`**:用于创建可以旋转的 `Drawable`。 9. **`AnimationDrawable`**:这种 `Drawable` 类型用于实现帧动画效果,通过连续...

    玩转Android之Drawable的使用

    【玩转Android之Drawable的使用】 Drawable在Android开发中扮演着至关重要的角色,它是图形和图像的基础元素,广泛用于UI设计和自定义视图。在Android中,Drawable不仅仅局限于简单的图片,还包括各种复杂的图形和...

    Android:Drawbale

    7. ScaleDrawable:缩放图,可以动态地改变`Drawable`的大小。 8. AnimationDrawable:动画图,可以播放一系列的`Drawable`来创建帧动画效果。 二、Drawable的使用 1. 在XML中定义:通过在res/drawable目录下创建...

    自定义RaingBar

    如果需要更复杂的样式,可以创建一个Drawable资源,如Shape Drawable,它允许定义形状(如矩形、圆形)、边框、填充色等。通过在Drawable中定义多个层,我们可以实现填充星和空心星的切换。在RatingBar的XML布局中...

    Android实战页面内容加载动画

    在"DrawableAnimation"这个压缩包文件中,可能包含了上述几种Drawable动画的示例代码或者资源文件。开发者可以通过解析和理解这些文件,学习如何在代码中实例化和启动这些Drawable动画,以及如何将它们应用于UI组件...

    水波纹效果

    一种常见的做法是使用`android.graphics.drawable.ScaleDrawable`或自定义View。例如,可以创建一个自定义的View,监听触摸事件,然后在触摸位置画出半透明圆圈并逐渐扩大,模拟水波纹扩散的过程。 ```java public ...

    11、可绘制类1

    首先,BitmapDrawable是Drawable类的一个子类,主要用于处理位图资源。它可以增加位图的属性,比如设置位图是否启用抗锯齿、是否进行抖动处理、是否应用过滤等。此外,BitmapDrawable还能在填充背景时定义不同的重复...

    Drawble的7种图像处理方式demo:shape、layers、scale、bitmap、等

    Bitmap Drawables处理的是像素级别的图像,通常是从资源文件、网络或者内存中加载。Bitmap提供了丰富的操作方法,如裁剪、旋转、颜色转换等。在Android中,位图的使用需要注意内存管理和性能优化,因为大图可能会...

Global site tag (gtag.js) - Google Analytics