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有很多种,有的时候 ...
随机推荐
- C. Bear and Colors 区间枚举的技巧
http://codeforces.com/problemset/problem/673/C 先说一个枚举区间的技巧,枚举前缀,不要枚举后缀. 就是下面这个代码是不好的 ; i <= n; ++ ...
- log4go折腾
导包 go get -u github.com/alecthomas/log4go log4go.xml配置 <logging> <filter enabled="true ...
- AJPFX总结private关键字
private关键字 什么是private关键字? 它是一个修饰符,代表私有的意思,它可以修饰成员变量和成员方法 private关键字的特点? ...
- c# 从DataGridVieew导出到excel
public static bool DataGridViewToExcel(DataGridView dataGridView, bool isShowExcel) { int rowsQty = ...
- 四次元新浪微博客户端Android源码
四次元新浪微博客户端Android源码 源码下载:http://code.662p.com/list/11_1.html [/td][td] [/td][td] [/td][td] 详细说明:http ...
- 3.12 在运算和比较时使用NULL值
问题:NULL值永远不会等于或不等于任何值,也包括NULL值自己,但是需要像计算真实值一样计算可为空列的返回值.例如,需要在表emp中查出所有比“WARD”提成(COMM)低的员工,提成为NULL(空 ...
- Python100天打卡-Day10-图形用户界面和游戏开发
基于tkinter模块的GUIPython默认的GUI开发模块是tkinter(在Python 3以前的版本中名为Tkinter)使用tkinter来开发GUI应用需要以下5个步骤: 导入tkinte ...
- Django 你需要了解的入门操作
创建一个django project (我的版本是1.11.11) django-admin startproject mysite cd mysite 当前目录下会生成mysite的工程,目录结 ...
- java_日期和时间
1.System类中的currentTimeMillis:1970年1.1到现在的毫秒数 public class DateTest { public static void main(String[ ...
- mysql数据库优化 几个思路
建表: 合理的索引, 组合索引 合理的字段类型 合理的表结构和表关联关系 查询: 避免: *, 函数 , 计算 , like左右全匹配 , in , beteewn?? 索引和组合索引 子查询 ...