AnimatedRotateDrawable的简单使用

来源:互联网 发布:人力资源管理专业知乎 编辑:程序博客网 时间:2024/06/06 01:48

本篇是关于Drawable的第十二篇博客了,我都不知怎么介绍这个Drawable,只能说是自带旋转动画特效,如果你使用了AnimatedRotateDrawable作为背景,背景的绕着指定的旋转中心进行旋转。如果没有设置的话,旋转中心为drawable的左上角坐标。AnimatedRotateDrawable这个类很奇怪,不能直接在代码中使用,这个类使用@hide注释,第三方应用只能通过xml声明AnimatedRotateDrawable。好了,废话不多说了,直接看效果吧!
图片旋转tupai

主布局文件:

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_main"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context="com.example.animatedrotatedrawable.MainActivity">    <TextView        android:layout_centerInParent="true"        android:gravity="center"        android:background="@drawable/animated_rotate_drawable"        android:id="@+id/tv"        android:layout_width="200dp"        android:layout_height="200dp"        android:text="Hello World!" /></RelativeLayout>

animated_rotate_drawable.xml

<?xml version="1.0" encoding="utf-8"?><animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"    android:pivotX="50%"    android:pivotY="50%"    android:drawable="@drawable/fifth"></animated-rotate>

其中pivotX、pivotY用于指定旋转中心的位置,50%代表的是宽/高的一半,在这个实例中代表的就是drawable的中心点位置。

java文件就不给出来了,默认生成的java文件就行了!!

这是我的微信公众号,如果可以的话,希望您可以帮忙关注一下,这将是对我最大的鼓励了,谢谢!!

公众号

代码地址:
AnimatedRotateDrawable地址,地址比较杂,需要您自行提取!!

0 0