当前位置:  编程技术>移动开发
本页文章导读:
    ▪【通译】(76)视图动画        【翻译】(76)视图动画 【翻译】(76)视图动画   see http://developer.android.com/guide/topics/graphics/view-animation.html   原文见 http://developer.android.com/guide/topics/graphics/view-animation.html   --------------------------.........
    ▪ 怎么使用9.png        如何使用9.png 1.首先找到得到.png的图片,(可以通过别人的APK,或者PS) 2.打开Draw 9-patch(\android-sdk\tools\draw9patch.bat)     左边的File->open 9-patch打开.png的图标   在图片的周围画线,右边会显.........
    ▪ 【通译】(77)可绘画对象动画       【翻译】(77)可绘画对象动画 【翻译】(77)可绘画对象动画   see http://developer.android.com/guide/topics/graphics/drawable-animation.html   原文见 http://developer.android.com/guide/topics/graphics/drawable-animation.html   .........

[1]【通译】(76)视图动画
    来源: 互联网  发布时间: 2014-02-18
【翻译】(76)视图动画

【翻译】(76)视图动画

 

see

http://developer.android.com/guide/topics/graphics/view-animation.html

 

原文见

http://developer.android.com/guide/topics/graphics/view-animation.html

 

-------------------------------

 

View Animation

 

视图动画

 

You can use the view animation system to perform tweened animation on Views. Tween animation calculates the animation with information such as the start point, end point, size, rotation, and other common aspects of an animation.

 

你可以使用视图动画系统以执行View上的补间动画。补间动画使用一些信息诸如开始点、结束点、大小、旋转和一个动画的其它一般方面来计算动画。

 

A tween animation can perform a series of simple transformations (position, size, rotation, and transparency) on the contents of a View object. So, if you have a TextView object, you can move, rotate, grow, or shrink the text. If it has a background image, the background image will be transformed along with the text. The animation package provides all the classes used in a tween animation.

 

一个补间动画可以在一个View对象的内容上执行一系列简单变换(位置,大小,旋转,和透明度)。所以,如果你拥有一个TextView对象,你可以移动,旋转,增高,或缩短该文本。如果它拥有一个背景图片,背景图片将伴随文本而被变换。animation包提供在一个补间动画中使用的所有类。

 

A sequence of animation instructions defines the tween animation, defined by either XML or Android code. As with defining a layout, an XML file is recommended because it's more readable, reusable, and swappable than hard-coding the animation. In the example below, we use XML. (To learn more about defining an animation in your application code, instead of XML, refer to the AnimationSet class and other Animation subclasses.)

 

一个动画指令序列定义补间动画,通过XML或Android代码来定义。正如定义一个布局所用的,建议使用一个XML文件,因为它必手工编码动画更可读,可重用,以及可交换。在下面的示例中,我们使用XML。(要想知道关于在你的应用程序代码中定义一个动画的更多信息,而非使用XML,请参考AnimationSet类以及其它Animation子类。)

 

The animation instructions define the transformations that you want to occur, when they will occur, and how long they should take to apply. Transformations can be sequential or simultaneous - for example, you can have the contents of a TextView move from left to right, and then rotate 180 degrees, or you can have the text move and rotate simultaneously. Each transformation takes a set of parameters specific for that transformation (starting size and ending size for size change, starting angle and ending angle for rotation, and so on), and also a set of common parameters (for instance, start time and duration). To make several transformations happen simultaneously, give them the same start time; to make them sequential, calculate the start time plus the duration of the preceding transformation.

 

动画指定定义你希望发生的变换,当它们将发生时,以及它们将花多长时间应用。变换可以是串行或并行的——例如,你可以让一个TextView的内容从左移动到右,然后旋转180度,或者你可以让文本同时移动并旋转。每个变换持有特定用于那个变换的一组参数(开始大小和结束大小用于大小改变,开始角度和结束角度用于旋转,等等),还有一组通用参数(例如,开始时间和持续时间)。为了让几个变换同时发生,给它们相同的开始时间;为了令它们依次发生,计算开始时间加上前一个变换的持续时间。

 

The animation XML file belongs in the res/anim/ directory of your Android project. The file must have a single root element: this will be either a single <alpha>, <scale>, <translate>, <rotate>, interpolator element, or <set> element that holds groups of these elements (which may include another <set>). By default, all animation instructions are applied simultaneously. To make them occur sequentially, you must specify the startOffset attribute, as shown in the example below.

 

动画XML文件归入你的Android工程的res/anim/目录。文件必须拥有一个根元素:它将是其中一个单一的<alpha>,<scale>,<translate>,<rotate>,插值器元素,或持有这些元素分组的<set>元素(它可以包含另一个<set>)。默认,所有动画指定被同时应用。为了让它们依次地发生,你必须指定startOffset属性,正如下面的示例中所示。

 

The following XML from one of the ApiDemos is used to stretch, then simultaneously spin and rotate a View object.

 

以下出自其中一个API演示的XML被用于拉伸,然后同时拉长(注:spin也有旋转的意思)并旋转一个View对象。

 

-------------------------------

 

<set android:shareInterpolator="false">

    <scale

        android:interpolator="@android:anim/accelerate_decelerate_interpolator"

        android:fromXScale="1.0"

        android:toXScale="1.4"

        android:fromYScale="1.0"

        android:toYScale="0.6"

        android:pivotX="50%"

        android:pivotY="50%"

        android:fillAfter="false"

        android:duration="700" />

    <set android:interpolator="@android:anim/decelerate_interpolator">

        <scale

           android:fromXScale="1.4"

           android:toXScale="0.0"

           android:fromYScale="0.6"

           android:toYScale="0.0"

           android:pivotX="50%"

           android:pivotY="50%"

           android:startOffset="700"

           android:duration="400"

           android:fillBefore="false" />

        <rotate

           android:fromDegrees="0"

           android:toDegrees="-45"

           android:toYScale="0.0"

           android:pivotX="50%"

           android:pivotY="50%"

           android:startOffset="700"

           android:duration="400" />

    </set>

</set>

 

-------------------------------

 

Screen coordinates (not used in this example) are (0,0) at the upper left hand corner, and increase as you go down and to the right.

 

屏幕坐标(在这个示例中未使用)是在左上角的(0, 0),并且随着你向下走(注:待考)而增加并向右。

 

Some values, such as pivotX, can be specified relative to the object itself or relative to the parent. Be sure to use the proper format for what you want ("50" for 50% relative to the parent, or "50%" for 50% relative to itself).

 

一些值,诸如pivotX,可以相对于对象自身或相对于父对象来指定。确保使用正确的格式用于你想要的东西("50"表示相对于父对象的50%,或者"50%"表示相对于它自身的50%)。

 

You can determine how a transformation is applied over time by assigning an Interpolator. Android includes several Interpolator subclasses that specify various speed curves: for instance, AccelerateInterpolator tells a transformation to start slow and speed up. Each one has an attribute value that can be applied in the XML.

 

你可以通过赋予一个Interpolator来决定一个变换如何随时间过去而被应用。Android包含几个Interpolator子类,它们指定不同速度的曲线:例如,AccelerateInterpolator告诉变换缓慢开始然后加速。每个(注:每个插值器?)拥有可以在XML中应用的一个属性值。

 

With this XML saved as hyperspace_jump.xml in the res/anim/ directory of the project, the following code will reference it and apply it to an ImageView object from the layout.

 

带有在工程的res/anim/目录中保存为hyperspace_jump.xml的XML,以下代码将引用它并应用它到来自布局的一个ImageView对象。

 

-------------------------------

 

ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage);

Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);

spaceshipImage.startAnimation(hyperspaceJumpAnimation);

 

-------------------------------

 

As an alternative to startAnimation(), you can define a starting time for the animation with Animation.setStartTime(), then assign the animation to the View with View.setAnimation().

 

作为对startAnimation()的一个替换方案,你可以用Animation.setStartTime()为动画定义一个开始时间,然后用View.setAnimation()赋予动画给该View。

 

For more information on the XML syntax, available tags and attributes, see Animation Resources.

 

想获得关于XML语法,可用的标签以及属性的更多信息,参见动画资源。

 

-------------------------------

 

Note: Regardless of how your animation may move or resize, the bounds of the View that holds your animation will not automatically adjust to accommodate it. Even so, the animation will still be drawn beyond the bounds of its View and will not be clipped. However, clipping will occur if the animation exceeds the bounds of the parent View.

 

注意:不管你的动画可以如何移动或改变大小,持有你的动画的View的范围将不会自动地调整以适应它。虽然如此,动画将仍然超出它的视图的范围而被绘画并且将不被剪裁。然而剪裁将发生,如果动画超出父View的范围。

 

-------------------------------

 

Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.

 

除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。

 

Android 4.0 r1 - 08 Mar 2012 0:34

 

-------------------------------

 

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

 

(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)

 

(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:

* ソフトウェア技術ドキュメントを勝手に翻訳

http://www.techdoctranslator.com/android

* Ley's Blog

http://leybreeze.com/blog/

* 农民伯伯

http://www.cnblogs.com/over140/

* Android中文翻译组

http://androidbox.sinaapp.com/



    
[2] 怎么使用9.png
    来源: 互联网  发布时间: 2014-02-18
如何使用9.png

1.首先找到得到.png的图片,(可以通过别人的APK,或者PS)

2.打开Draw 9-patch(\android-sdk\tools\draw9patch.bat)

 


 

左边的File->open 9-patch打开.png的图标

 

在图片的周围画线,右边会显示实时效果。线需要是连续的,按住shift可以擦出

 

上下左右的线有特定的意义

 

左边 是垂直方向可以伸缩的区域
上边 是水平方向可以伸缩的区域
右边 是垂直方向的内容区域
下边 是水平方向的内容区域

 

 

这个工具不能改变图片本身的特性,只能规定缩放的区域!如果要改变图片本身的特性(比如,颜色,大小,翻转。。),需要在别的软件,比如Ps中完成

 

 

画好后保存就好了,它会自动保存为.9.png的格式就可以使用了

 

 

如果运行的时候出现黑边,看看是不是上下左右都有画线。如果没有的话可能就会出现黑边

 

 

 

 


    
[3] 【通译】(77)可绘画对象动画
    来源: 互联网  发布时间: 2014-02-18
【翻译】(77)可绘画对象动画

【翻译】(77)可绘画对象动画

 

see

http://developer.android.com/guide/topics/graphics/drawable-animation.html

 

原文见

http://developer.android.com/guide/topics/graphics/drawable-animation.html

 

-------------------------------

 

Drawable Animation

 

可绘画对象动画

 

Drawable animation lets you load a series of Drawable resources one after another to create an animation. This is a traditional animation in the sense that it is created with a sequence of different images, played in order, like a roll of film. The AnimationDrawable class is the basis for Drawable animations.

 

可绘画对象动画让你一个接一个地加载一系列Drawable资源以创建一个动画。从它是用一系列不同的图片创建,依次地播放,就像一卷胶卷(注:电影)的意义上看,这是一种传统动画。AnimationDrawable类是可绘画对象动画的基础。

 

While you can define the frames of an animation in your code, using the AnimationDrawable class API, it's more simply accomplished with a single XML file that lists the frames that compose the animation. The XML file for this kind of animation belongs in the res/drawable/ directory of your Android project. In this case, the instructions are the order and duration for each frame of the animation.

 

然而你可以在你的代码中定义一个动画的帧,使用AnimationDrawable类的API,用一个列举组成动画的帧的单一XML文件来实现会更简单。用于此类型动画的XML文件归入你的Android工程的res/drawable/目录。在这种情况下,指令是动画每个帧的次序和持续时间。

 

The XML file consists of an <animation-list> element as the root node and a series of child <item> nodes that each define a frame: a drawable resource for the frame and the frame duration. Here's an example XML file for a Drawable animation:

 

XML文件由作为根节点的一个<animation-list>元素以及一系列子<item>节点组成,每个子节点定义一个帧:一个用于该帧的可绘画对象资源和帧持续时间。这里有一个用于可绘画对象动画的示例XML文件:

 

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"

    android:oneshot="true">

    <item android:drawable="@drawable/rocket_thrust1" android:duration="200" />

    <item android:drawable="@drawable/rocket_thrust2" android:duration="200" />

    <item android:drawable="@drawable/rocket_thrust3" android:duration="200" />

</animation-list>

 

This animation runs for just three frames. By setting the android:oneshot attribute of the list to true, it will cycle just once then stop and hold on the last frame. If it is set false then the animation will loop. With this XML saved as rocket_thrust.xml in the res/drawable/ directory of the project, it can be added as the background image to a View and then called to play. Here's an example Activity, in which the animation is added to an ImageView and then animated when the screen is touched:

 

这个动画只运行三帧。通过设置列表的android:oneshot属性为true,它将只循环一次然后停止并保持在最后一帧上。如果它被设置为false,那么动画将循环。使用这个在工程的res/drawable/目录中保存为rocket_thrust.xml的XML,它可以被添加到一个View作为背景图片,然后被调用以播放。这里有一个示例Activity,在它里面该动画被添加到一个ImageView然后在屏幕被触碰时被动画化。

 

AnimationDrawable rocketAnimation;

 

public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.main);

 

  ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);

  rocketImage.setBackgroundResource(R.drawable.rocket_thrust);

  rocketAnimation = (AnimationDrawable) rocketImage.getBackground();

}

 

public boolean onTouchEvent(MotionEvent event) {

  if (event.getAction() == MotionEvent.ACTION_DOWN) {

    rocketAnimation.start();

    return true;

  }

  return super.onTouchEvent(event);

}

 

It's important to note that the start() method called on the AnimationDrawable cannot be called during the onCreate() method of your Activity, because the AnimationDrawable is not yet fully attached to the window. If you want to play the animation immediately, without requiring interaction, then you might want to call it from the onWindowFocusChanged() method in your Activity, which will get called when Android brings your window into focus.

 

重要的是注意被调用在AnimationDrawable上的start()方法不能在你的Activity的onCreate()方法期间被调用,因为AnimationDrawable还没有被完全依附到窗口。如果你希望立即播放动画,不需要交互,那么你可能希望从你的Activity中的onWindowFocusChanged()方法里调用它,它(注:指onWindowFocusChanged())将在Android带你的窗口进入焦点时被调用。

 

For more information on the XML syntax, available tags and attributes, see Animation Resources.

 

想获得关于XML语法,可用的标签和属性的更多信息,参见动画资源。

 

Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.

 

除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。

 

Android 4.0 r1 - 08 Mar 2012 0:34

 

-------------------------------

 

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

 

(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)

 

(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:

* ソフトウェア技術ドキュメントを勝手に翻訳

http://www.techdoctranslator.com/android

* Ley's Blog

http://leybreeze.com/blog/

* 农民伯伯

http://www.cnblogs.com/over140/

* Android中文翻译组

http://androidbox.sinaapp.com/

 


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android Touch事件分发过程详解 iis7站长之家
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3