Android ScaleDrawable
顾名思义,Android ScaleDrawable实现一个drawable的缩放。写一个例子。
一个线性布局,垂直放几个ImageView,然后依次缩放若干个ScaleDrawable。
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="zhangphil.app.MainActivity"> <ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/imageView1" /> <ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/imageView2" /> <ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/imageView3" /> <ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/imageView4" /> </LinearLayout>
Java代码:
package zhangphil.app; import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.ScaleDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.ImageView; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); ColorDrawable drawable1=new ColorDrawable(Color.RED);
drawable1.setLevel(1);
ImageView image1= (ImageView) findViewById(R.id.imageView1);
image1.setImageDrawable(drawable1); ColorDrawable drawable2=new ColorDrawable(Color.YELLOW);
drawable2.setLevel(1);
ScaleDrawable sd2 = new ScaleDrawable(drawable2, Gravity.LEFT,0.1f,0.0f);
ImageView image2= (ImageView) findViewById(R.id.imageView2);
image2.setImageDrawable(sd2); ColorDrawable drawable3=new ColorDrawable(Color.BLUE);
drawable3.setLevel(1);
ScaleDrawable sd3 = new ScaleDrawable(drawable3, Gravity.LEFT,0.2f,0.0f);
ImageView image3= (ImageView) findViewById(R.id.imageView3);
image3.setImageDrawable(sd3); ColorDrawable drawable4=new ColorDrawable(Color.GREEN);
drawable4.setLevel(1);
ScaleDrawable sd4 = new ScaleDrawable(drawable4, Gravity.LEFT,0.3f,0.0f);
ImageView image4= (ImageView) findViewById(R.id.imageView4);
image4.setImageDrawable(sd4);
}
}
代码运行结果:
以上ScaleDrawable没有让drawable的高度缩放,只缩放宽度。
附录:
1,《Android ImageView的setImageLevel和level-list使用简介》链接:http://blog.csdn.net/zhangphil/article/details/48936209
Android ScaleDrawable的更多相关文章
- 【腾讯Bugly干货分享】Android ImageView 正确使用姿势
本文来自于腾讯bugly开发者社区,未经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/5832602d7196970d65901d76 导语 本文主要介绍了ImageV ...
- Android的各种Drawable 讲解 大全
Android把可绘制的对象抽象为Drawable,不同的图形图像资源就代表着不同的drawable类型.Android FrameWork提供了一些具体的Drawable实现,通常在代码中都不会直接 ...
- Android 自定义Drawable
1.使用BitmapShader实现图片圆角 public class CornerDrawable extends Drawable { private Paint mPaint; private ...
- Android Drawable的9种子类 介绍
原文: Android Drawable的9种子类 介绍 Drawable 在android里面 就是代表着图像,注意是图像 而不是图片. 图片是图像的子集.图像除了可以包含图片以外 还可以包含颜 ...
- Android Drawable资源
Android实现应用d动画效果:比如App第一次打开的开始动画等 有两种:GIF动画和代码实现. 第一种:借助于Gif制作工具软件实现.一般是和第三方开源的GifView(https://githu ...
- 【转】Android Drawable Resource学习(十一)、RotateDrawable
对另一个drawable资源,基于当前的level,进行旋转的drawable. 文件位置: res/drawable/filename.xml文件名即资源名 编译数据类型: 指向 RotateDra ...
- 十二、Android UI开发专题(转)
http://dev.10086.cn/cmdn/bbs/viewthread.php?tid=18736&page=1#pid89255Android UI开发专题(一) 之界面设计 近期很 ...
- Android 常用UI控件之TabHost(2)简单示例
1,布局 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tool ...
- 玩转Android之Drawable的使用
Drawable天天用,可你是否对Drawable家族有一个完整的认知?今天我们就来系统的学习一下Drawable的使用. 1.概述 用过Drawable的筒子都知道Drawable有很多种,有的时候 ...
随机推荐
- 正则表达式exec方法的陷阱
http://www.w3school.com.cn/jsref/jsref_exec_regexp.asp exec() 方法的功能非常强大,它是一个通用的方法,而且使用起来也比 test() 方法 ...
- iOS UILabel UITextView自适应文本,或文本大小自适应
//UILabel自适应文本的高度 UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(, , , )]; label.numberOf ...
- C8051特点
C8051与传统51的区别在于优先权交叉开关.系统时钟.SFR寄存器几个方面: 一 优先权交叉开关:传统的51外设功能是固定分配或者复用分配到指定引脚,而C8051则是通过优先权交叉开关设置,即要想分 ...
- PT2264解码心得
PT2264解码心得 最近闲暇时间在琢磨无线RF解码程序,正好在数码之家论坛中翻出大佬的解码程序(http://bbs.mydigit.cn/read.php?tid=245739),于是乎,慢慢学习 ...
- poj2441 Arrange the Bulls
思路: 状态压缩dp.需要一点优化,否则容易超时. 实现: #include <cstdio> #include <vector> #include <cstring&g ...
- 洛谷P3773 [CTSC2017]吉夫特(Lucas定理,dp)
题意 满足$b_1 < b_2 < \dots < b_k$且$a_{b_1} \geqslant a_{b_2} \geqslant \dots \geqslant a_{b_k} ...
- Java虚拟机性能调优相关
一.JVM内存模型及垃圾收集算法 1.根据Java虚拟机规范,JVM将内存划分为:New(年轻代)Tenured(年老代)永久代(Perm) 其中New和Tenured属于堆内存,堆内存会从JVM启动 ...
- Netbeans Makefile: recipe for target 'XXX' failed 运行failed(退出值 -1073741511 找不到C/C++库文件,关键字
今天不知怎么的又出错了 吐血了 找不到NULL new等关键字了 看到知乎上有人和我一个问题,怎么办?很简单卸载了以前的cygwin和netbeans然后重装,我重装时没有把以前的cygwin ...
- oracle补丁类型
名称 说明 Release ¤ 标准产品发布.如Oracle Database 10g Release 2的第一个发行版本为10.2.0.1,可以在OTN.edelivery等站点上公开下载 Patc ...
- Django请求,响应,ajax以及CSRF问题
二.request对象常用属性: Attribute Description path 请求页面的全路径,不包括域名端口参数.例如: /users/index method 一个全大写的字符串,表示请 ...