【转】Android Drawable Resource学习(十一)、RotateDrawable
对另一个drawable资源,基于当前的level,进行旋转的drawable。
- 文件位置:
res/drawable/filename.xml
文件名即资源名- 编译数据类型:
- 指向
RotateDrawable的指针。 - 资源引用:
- In Java:
R.drawable.filename
In XML:@[package:]drawable/filename - 语法:
-
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable=""
android:visible=""
android:fromDegrees=""
android:toDegrees=""
android:pivotX=""
android:pivotY=""/>
元素:
- <rotate>
-
定义一个RotateDrawable,必须作为根元素。
属性:
xmlns:android- String类型。 必须的。定义XML文件的命名空间。必须是
"http://schemas.android.com/apk/res/android". android:drawable-
Drawable 资源。必须的。引用一个drawable资源。
android:visible- Boolean。是否可见。
android:fromDegrees- 整形。 从多少的角度开始旋转
android:toDegrees- 整形。 到多少的角度结束旋转
android:pivotX- 百分比。 旋转的中心在图片X轴的百分比
android:visible- 百分比。 旋转的中心在图片Y轴的百分比
-
- 参考:
示例和解释:
坐标的信息如下:

1、原始图片如下:

2、在 scale.xml文件中定义如下:
- <?xml version="1.0" encoding="utf-8"?>
- <rotate xmlns:android="http://schemas.android.com/apk/res/android"
- android:drawable="@drawable/image02"
- android:visible="true"
- android:fromDegrees="-90"
- android:toDegrees="180"
- android:pivotX="50%"
- android:pivotY="50%">
- </rotate>
那么,图片的初始角度为-90。即如下:

要旋转到的角度如下:

并且是顺时针旋转。
3、那么图片将从-90到180进行旋转。level值为10000,也就是说level每加1000,即顺时针旋转270/10000*1000=27度。
可以根据显示看出来效果。
- public class MainActivity extends Activity{
- RotateDrawable rotateDrawable;
- int level=0;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ImageView imageView=(ImageView)findViewById(R.id.imgView);
- rotateDrawable=(RotateDrawable)imageView.getDrawable();
- thread.start();
- }
- Thread thread=new Thread(new Runnable() {
- public void run() {
- while (level<=10000) {
- handler.sendEmptyMessage(0x00);
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- });
- Handler handler=new Handler(){
- public void handleMessage(Message msg) {
- Toast.makeText(MainActivity.this, level+"", 500).show();
- rotateDrawable.setLevel(level);
- level+=1000;
- };
- };
- }
- from:http://blog.csdn.net/lonelyroamer/article/details/8252533
【转】Android Drawable Resource学习(十一)、RotateDrawable的更多相关文章
- android Drawable Resource学习
转载自: http://blog.csdn.net/true100/article/details/52316423 http://blog.csdn.net/true100/article/deta ...
- Android Drawable绘图学习笔记(转)
如何获取 res 中的资源 数据包package:android.content.res 主要类:Resources Android SDK中的简介:Class for accessing an ap ...
- Android Studio 之 用 Drawable resource file 美化 Button 样式
shape •新建 Drawable resource file 点击 app/src/main/res 找到 drawable 文件夹,右击->New->Drawable Resourc ...
- Android Drawable 与 LayerList综合汇总
先看需求.要求这样的效果 上代码 <?xml version="1.0" encoding="utf-8"? > <layer-list xm ...
- Drawable(1)各种Drawable Resource介绍
简介 Drawable Resources(可绘资源) 是一系列可以在屏幕上被绘制的资源文件,它不只是图片,可以是 xml文件,在xml文件中配置各种绘制参数. 常见Drawable Resource ...
- Android Drawable Mipmap Vector使用及Vector兼容
原文地址:http://blog.csdn.net/eclipsexys/article/details/51838119 http://blog.csdn.net/qq_15545283/artic ...
- Android Drawable 详解(教你画画!)
参考 1.Android中的Drawable基础与自定义Drawable 2.android中的drawable资源 3.Android开发之Shape详细解读 Drawable分类 No xml标签 ...
- Android -- Drawable与Bitmap测试
Drawable 以下这个是测试加载10 ...
- Android Drawable系列(1):自定义背景以及注意事项
0. Shape自身属性 android:shape=["rectangle" | "oval" | "line" | "ring ...
随机推荐
- mac上安装MySQL
mysql 官网下载http://dev.mysql.com/downloads/mysql/ 注意安装mysql-5.5.17-osx10.6-x86_64.dmg这样安装方便设置系统安全权限后 点 ...
- 英文VS2010安装中文版MSDN文档方法
英文VS2010安装中文版MSDN文档方法 2010-06-01 11:52 by 李永京, 51409 阅读, 50 评论, 收藏, 编辑 在2010年4月12号发布Visual Studio 20 ...
- 2012开源项目计划-WPF企业级应用整合平台
2012开源项目计划-WPF企业级应用整合平台 开篇 2012年,提前祝大家新年快乐,为了加快2012年的开发计划,特打算年前和大家分享一下2012年的开发计划和年后具体的实施计划,希望有兴趣或者有志 ...
- ImportError: No module named 'commands'
/*********************************************************************** * ImportError: No module na ...
- vim-airline的theme
仓库位置: https://github.com/vim-airline/vim-airline-themes 这些内置的这些主题,可以直接使用,方法是在.vimrc中写 let g:airline_ ...
- Day05_JAVA语言基础第五天
1.函数(掌握) 1.概念(掌握) 定义在类中,有特定功能的一小段程序 2.格式(掌握) 修饰符 返回类型 函数名(参数类型 形式参数,...){ 函数体: return 返回值; } 解释: A 修 ...
- xcode中的一些快捷键
隐藏xcode command+h退出xcode command+q关闭窗口 command+w关闭所有窗口 command+option+w关闭当前项目 command+control+w关闭当前文 ...
- sql 语句累积
// 查询用户表 手机号对应不只一个用户的手机号列表 跟数量 (项目在运营后晚上偶尔出现 多个用户对应一个手机号的情况) select mobile,count(mobile) from go_m ...
- 如何让Android字体自适应屏幕分辨率
在不同的分辨率下,Android字体大小怎么自适应分辨率的变化? 假设需要适应320x240,480x320分辨率.在res目录下新建文件夹values-320x240, values-480x320 ...
- soapUI 在多个测试套件 testsuite 里,多个testcase里传值如何实现
1.首先 要添加一个全局 自定义变量 Custom Properties 2.用transfer property 将取来的值 放入到变量 getToken 里 3.在另一个testc ...