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有很多种,有的时候 ...
随机推荐
- XHTML 1.0 的三种 XML 文档类型 DOCTYPE
XHTML 1.0 的三种 XML 文档类型 XHTML 1.0 规定了三种 XML 文档类型 XHTML 1.0 Strict <!DOCTYPE html PUBLIC "-//W ...
- 475 Heaters 加热器
详见:https://leetcode.com/problems/heaters/description/ C++: class Solution { public: int findRadius(v ...
- RHEL 6.5----LVS(DR)
主机名 IP 所需软件 master eth0==>192.168.30.140(Nat) eth0:1==>192.168.17.130(Nat) ipvsadm node-1 et ...
- 用PDFMiner从PDF中提取文本文字
1.下载并安装PDFMiner 从https://pypi.python.org/pypi/pdfminer/下载PDFMineer wget https://pypi.python.org/pack ...
- Jenkins视图使用--添加删除视图
job建立的特别多的时候,我们可能不太容易找到自己的某个job,这时,我们就可以在Jenkins中建立视图.job的视图类似于我们电脑上的文件夹.可以通过一些过滤规则,将已经建好的job过滤到视图中, ...
- 05.NopCommerce给Topic表添加排序及类别字段
在用到Nopcommerce中静态页面表时,发现Topic表没有排序字段和类别字段,导致如果Page文件很多的话,无法区分是哪个类别,为此我稍微扩展了一下字段,在此记录一下操作流程,方便以后自己查看, ...
- 页面html图片按钮多种写法
原地址:http://blog.163.com/weison_hi/blog/static/17680404720118534033788/ 第一种: 在一般情况下按钮提交表单: <form i ...
- 秒杀Sublime Text的微软开源代码编辑工具Visual Studio Code
1. 下载链接: https://code.visualstudio.com/ 2. 秒开一个ASP.NET网站源码 3.编辑CSS颜色支持 4.Git支持 5.常用快捷键 Ctrl+Shift+P ...
- codevs 1979 第K个数
时间限制: 1 s 空间限制: 1000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定一个长度为N(0<n<=10000)的序列,保证每一个序列中的数字 ...
- Hadoop 安装过程中出现的问题
1.hadoop-daemon.sh start namenode 启动失败 查看hadoop/logs 下面的日志 出现 2017-04-11 15:35:13,860 WARN org.apach ...