Android player reflective Animation

Source: Internet
Author: User

MainActivity:


[Java]
Package smalt. play. show;
 
Import android. app. Activity;
Import android. OS. Bundle;
Import android. OS. Handler;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. view. animation. Animation;
Import android. view. animation. Animation. AnimationListener;
Import android. view. animation. AnimationUtils;
Import android. widget. ImageView;
 
Public class Splayer2Activity extends Activity {
ImageView ivImage;
ImageView ivPlay;
ImageView ivStop;
ImageView ivPre;
ImageView ivNext;
ImageView ivShuffer;
ImageView ivRepeat;
Animation playAnim; // play a video by category
Animation stopAnim; // you can call this operation when the player is playing.
Animation preAnim; // play a video by category
Animation nextAnim; // play a video by force
Animation shufferAnim; // play a video by category
Animation repeatAnim; // play a video by category
 
Void initView () {// Initialization
IvImage = (ImageView) findViewById (R. id. player_image );
IvPlay = (ImageView) findViewById (R. id. player_play );
IvStop = (ImageView) findViewById (R. id. player_stop );
IvNext = (ImageView) findViewById (R. id. player_next );
IvPre = (ImageView) findViewById (R. id. player_pre );
IvRepeat = (ImageView) findViewById (R. id. player_repeat );
IvShuffer = (ImageView) findViewById (R. id. player_shuffle );
 
}
 
Void initData () {// specifies the active response
 
DemoAnim ();
 
}
 
Void initListener () {// listener
PlayAnim. setAnimationListener (new AnimationListener (){
 
Public void onAnimationStart (Animation animation ){
// TODO Auto-generated method stub
 
}
 
Public void onAnimationRepeat (Animation animation ){
// TODO Auto-generated method stub
 
}
 
Public void onAnimationEnd (Animation animation ){
// Hide the widget after the notebook is completed
IvPlay. setVisibility (View. GONE );
IvStop. setVisibility (View. GONE );
IvPre. setVisibility (View. GONE );
IvNext. setVisibility (View. GONE );
IvRepeat. setVisibility (View. GONE );
IvShuffer. setVisibility (View. GONE );
}
});
IvImage. setOnClickListener (new OnClickListener (){
 
Public void onClick (View v ){
// Click it to display its cover
IvPlay. setVisibility (View. VISIBLE );
IvStop. setVisibility (View. VISIBLE );
IvPre. setVisibility (View. VISIBLE );
IvNext. setVisibility (View. VISIBLE );
IvRepeat. setVisibility (View. VISIBLE );
IvShuffer. setVisibility (View. VISIBLE );
}
});
}
 
Void demoAnim (){
// Dynamic Route
PlayAnim = AnimationUtils. loadAnimation (this, R. anim. play_out );
StopAnim = AnimationUtils. loadAnimation (this, R. anim. stop_out );
PreAnim = AnimationUtils. loadAnimation (this, R. anim. pre_out );
NextAnim = AnimationUtils. loadAnimation (this, R. anim. next_out );
ShufferAnim = AnimationUtils. loadAnimation (this, R. anim. shuffer_out );
RepeatAnim = AnimationUtils. loadAnimation (this, R. anim. repeat_out );
Handler mHandler = new Handler ();
MHandler. postDelayed (new Runnable (){
 
Public void run (){
IvPlay. startAnimation (playAnim );
IvStop. startAnimation (stopAnim );
IvPre. startAnimation (preAnim );
IvNext. startAnimation (nextAnim );
IvRepeat. startAnimation (repeatAnim );
IvShuffer. startAnimation (shufferAnim );
}
},2000 );
 
}
 
/** Called when the activity is first created .*/
 
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
InitView ();
InitData ();
InitListener ();
}
}

MainXML:

[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">
 
<RelativeLayout
Android: layout_width = "300dp"
Android: layout_height = "300dp"
Android: layout_centerInParent = "true">
 
<! -- Zookeeper tablets -->
 
<ImageView
Android: id = "@ + id/player_image"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: layout_centerInParent = "true"
Android: src = "@ drawable/player_image"
Android: text = "zookeeper"/>
<! -- Play -->
 
<ImageView
Android: id = "@ + id/player_play"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_alignParentTop = "true"
Android: layout_centerHorizontal = "true"
Android: paddingTop = "10dp"
Android: src = "@ drawable/player_play_light"/>
<! -- Stop -->
 
<ImageView
Android: id = "@ + id/player_stop"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_alignParentBottom = "true"
Android: layout_centerHorizontal = "true"
Android: paddingBottom = "10dp"
Android: src = "@ drawable/player_stop_light"/>
<! -- Previous song -->
 
<ImageView
Android: id = "@ + id/player_pre"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_alignParentLeft = "true"
Android: layout_centerVertical = "true"
Android: paddingLeft = "10dp"
Android: src = "@ drawable/player_prev_light"/>
<! -- Next song -->
 
<ImageView
Android: id = "@ + id/player_next"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_alignParentRight = "true"
Android: layout_centerVertical = "true"
Android: paddingRight = "10dp"
Android: src = "@ drawable/player_next_light"/>
<! -- Upper right terminal -->
 
<ImageView
Android: id = "@ + id/player_shuffle"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_alignParentRight = "true"
Android: paddingRight = "10dp"
Android: paddingTop = "10dp"
Android: src = "@ drawable/player_shuffle_off"/>
<! -- Playback in sequence on the top left -->
 
<ImageView
Android: id = "@ + id/player_repeat"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_alignParentLeft = "true"
Android: paddingLeft = "10dp"
Android: paddingTop = "10dp"
Android: src = "@ drawable/player_repeat_off"/>
</RelativeLayout>
 
</RelativeLayout>

The animation effect is similar. Only one instance is attached:

[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android">
 
<Alpha
Android: duration= "2500"
Android: fromalphi = "1.0"
Android: toAlpha = "0.0"/>
 
<Translate
Android: duration= "2500"
Android: fromXDelta = "0% p"
Android: fromYDelta = "0% p"
Android: toXDelta = "-800% p"
Android: toYDelta = "0% p"/>
 
<! --
<Scale
Android: duration= "3000"
Android: fillAfter = "true"
Android: fromXScale = "0"
Android: fromYScale = "0"
Android: toXScale = "1.0"
Android: toYScale = "1.0"/>
 
 
 
 
 
-->
 
</Set>

Effect: all controls slide to the center and disappear. Click the album cover to display it again.

Author: yhm2046

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.