android 属性动画应用,不知道这个效果好看,反正挺好玩的!
来源:互联网 发布:美国经济数据发布日 编辑:程序博客网 时间:2024/05/01 06:28
前两天为了看漫画,下载了一个动漫APP,打开一看,滑动的时候竟然下面的TAB跟上面的TITEL都隐藏掉了,变成全屏了,感觉好牛逼的样子哦,当初我以为是隐藏跟现实的属性那,后来一仔细看,不是,那么只有动画来实现了,看来还得用属性动画来实现:属性动画嘛就是改变了对象的属性了。不知道这个效果好不好,应该适合一些全屏阅读类的app.
先看看它的效果:
在看看咱们的效果:
好了 ,代码很少就能实现这个效果:
- 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")
- @Override
- protected 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;
- @Override
- public 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;
- }
- }
- }
- <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="match_parent"
- 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="标题"
- 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="标题"
- android:textColor="#ffffff"
- android:textSize="18sp" />
- </LinearLayout>
- </RelativeLayout>
- </FrameLayout>
好玩!
android 属性动画应用,不知道这个效果好看,反正挺好玩的!
分类: Android知识点2015-04-24 09:47 132人阅读 评论(4) 收藏 举报
android标题栏滑动隐藏属性动画ViewPropertyAnimator滑动隐藏
前两天为了看漫画,下载了一个动漫APP,打开一看,滑动的时候竟然下面的TAB跟上面的TITEL都隐藏掉了,变成全屏了,感觉好牛逼的样子哦,当初我以为是隐藏跟现实的属性那,后来一仔细看,不是,那么只有动画来实现了,看来还得用属性动画来实现:属性动画嘛就是改变了对象的属性了。不知道这个效果好不好,应该适合一些全屏阅读类的app.
先看看它的效果:
在看看咱们的效果:
好了 ,代码很少就能实现这个效果:
- 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")
- @Override
- protected 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;
- @Override
- public 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;
- }
- }
- }
- <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="match_parent"
- 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="标题"
- 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="标题"
- android:textColor="#ffffff"
- android:textSize="18sp" />
- </LinearLayout>
- </RelativeLayout>
- </FrameLayout>
好玩!
0 0
- android 属性动画应用,不知道这个效果好看,反正挺好玩的!
- android 属性动画应用,不知道这个效果好看,反正挺好玩的!
- 好看的android动画效果
- Android 好看的loading动画效果
- 不知道这里做数据化营销的多不多,反正我是做这个行业的
- 挺好玩的uniqueID&uniqueNumber属性
- android好看的加载动画
- 你不知道的Android 5.0转场共享动画实现炫酷效果
- Android 利用属性动画结合贝塞尔曲线方程编写好看的动画.
- 挺好玩的
- 九九乘法表挺好玩的
- 有两张图片挺好看的,不知道是什么意思。
- 挺好玩的C语句
- 挺好玩的C语句
- 打人游戏,挺好玩的
- Android属性动画弹出效果
- 你知道什么是数据结构吗?反正我不知道。
- 小游戏(名字不知道叫什么好,反正是好像打靶的那种游戏)
- hdu 4417 Super Mario/树套树
- Memcached深度分析
- 【个人收藏】Direct UI 与一个简单的开源DIRECTUI界面框架
- ArcGIS的基础
- 京东架构
- android 属性动画应用,不知道这个效果好看,反正挺好玩的!
- yuv encode h264 test
- win下安装Centos 6.5双系统过程附图(方案可行,最后描述了自己安装时启动项方面出现的问题)
- 应用层的一些通用服务使用的端口
- jabberd2 服务器启动脚本
- Github上的PHP资源汇总大全
- Maven和Maven插件
- windows下删除mongodb
- 亲测:删除MAC下文件夹中所有.svn文件的方法