本文主要是介绍android 属性动画应用,不知道这个效果好看,反正挺好玩的!,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
前两天为了看漫画,下载了一个动漫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;
}
}
}
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="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 属性动画应用,不知道这个效果好看,反正挺好玩的!的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!