Android property animation application. I don't know the effect. It's fun !, Android Animation

Source: Internet
Author: User
Tags gety

Android property animation application. I don't know the effect. It's fun !, Android Animation

Two days ago, I downloaded an animation APP to watch cartoons. When I opened it, the tabs below were hidden from the above TITEL and changed to full screen. I felt so awesome, I thought it was a hidden and realistic property. Later I took a closer look. No, it was only an animation. It seems that we have to use property animation to implement it: property animation changes the attributes of an object. I don't know whether the effect is good. It should be suitable for some full-screen reading apps.

Let's take a look at its effect:


Let's take a look at our results:


Well, the code can achieve this very little:

package com.example.hidetitle;import android.annotation.SuppressLint;import android.app.Activity;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.view.ViewPropertyAnimator;import android.view.View.OnTouchListener;import android.widget.ArrayAdapter;import android.widget.LinearLayout;import android.widget.ListView;public class MainActivity extends Activity {private boolean ismove  = true;private ViewPropertyAnimator animatebottom,animatetop;@SuppressLint("NewApi")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ListView mListView = (ListView) findViewById(R.id.my_listview);LinearLayout  tabbottom  = (LinearLayout) findViewById(R.id.tabbottom);LinearLayout  tabtop  = (LinearLayout) findViewById(R.id.tabtop);animatebottom = tabbottom.animate();animatetop = tabtop.animate();ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1);for (int i = 0; i < 100; i++) {adapter.add(i + "");}mListView.setAdapter(adapter);mListView.setOnTouchListener(new OnTouchListener() {private float y;private boolean down = true;private float lasty;@Overridepublic boolean onTouch(View v, MotionEvent event) {switch (event.getAction()) {case MotionEvent.ACTION_DOWN:y = event.getY();if (down) {lasty = y;}down = false;break;case MotionEvent.ACTION_MOVE:break;case MotionEvent.ACTION_UP:down = true;if (lasty - event.getY() < -5) {onScrollReset();} else if (lasty - event.getY() > 5) {onScroll();}break;}return false;}});}@SuppressLint("NewApi")public void onScroll() {if (ismove) {animatebottom.setDuration(500).translationY(200);animatetop.setDuration(500).translationY(-200);ismove = false;}}@SuppressLint("NewApi")public void onScrollReset() {if (!ismove) {animatebottom.setDuration(500).translationY(0);animatetop.setDuration(500).translationY(0);ismove = true;}}}
Xml:

<FrameLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "fill_parent" android: layout_height = "fill_parent"> <ListView android: id = "@ + id/my_listview" android: layout_width = "match_parent" android: layout_height = "match_parent"> </ListView> <RelativeLayout android: layout_width = "inline" android: layout_height = "match_parent"> <LinearLayout android: id = "@ + id/tabbottom" android: layout_width = "match_parent" android: layout_height = "50dip" android: layout_alignParentBottom = "true" android: background = "#880090D9" android: gravity = "center" android: orientation = "vertical"> <TextView android: id = "@ + id/textView1" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "title" android: textColor = "# ffffff" android: textSize = "18sp"/> </LinearLayout> <LinearLayout android: id = "@ + id/tabtop" android: layout_width = "match_parent" android: layout_height = "50dip" android: layout_alignParentTop = "true" android: background = "#880090D9" android: gravity = "center" android: orientation = "vertical"> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: text = "title" android: textColor = "# ffffff" android: textSize = "18sp"/> </LinearLayout> </RelativeLayout> </FrameLayout>


Fun!


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.