仿QQ空间视差效果,ListView.setHeader( )

根据listview的手指移动事件,动态设置listview上面的图片的宽高,并在手指放开的时候
实现图片的动画(随时间变化的动画值) ValueAnimator.ofInt ( )
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.animation.OvershootInterpolator;
import android.widget.ImageView;
import android.widget.ListView;
/**
* Created by lxj on 2017/1/5.
*/
public class ParallaxListView extends ListView {
public ParallaxListView(Context context) {
super(context);
}
public ParallaxListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ParallaxListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
int originalHeight;//最初的高度,就是120dp
ImageView image;
int maxHeight;//小孩的最大高度,就是设定为图片本身的高度
public void setParallaxImage(ImageView image){
this.image = image;
//从dimens文件中读取image_height的值,并自动转为像素
originalHeight = getResources().getDimensionPixelSize(R.dimen.image_height);
maxHeight = this.image.getDrawable().getIntrinsicHeight();
}
/**
* 该方法是在listview滑动到头的时候执行,并且可以在该方法中获取到手指移动的距离
* @param deltaY 手指移动的距离,顶部到头是负值,底部到头是正值
* @param scrollY scrollTo滚动的坐标
* @param maxOverScrollY listview滑到头之后可以继续滑动的最大距离
* @param isTouchEvent 是否是手指拖动到头,true:是, false:表示是靠惯性滑动到头
* @return
*/
@Override
protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY,
int scrollRangeX, int scrollRangeY,
int maxOverScrollX, int maxOverScrollY,
boolean isTouchEvent) {
//如果是手指拖动到头,并且是顶部到头,其他忽略不处理
if(isTouchEvent && deltaY<0){
//让ImageView的高度随着手指移动而增高
int newHeight = image.getHeight() + Math.abs(deltaY)/3;
//限制newHeight
if(newHeight>maxHeight){
newHeight = maxHeight;
}
ViewGroup.LayoutParams params = image.getLayoutParams();
params.height = newHeight;
image.setLayoutParams(params);
}
return super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX,
scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if(ev.getAction()==MotionEvent.ACTION_UP){
//让ImageView的高度缓慢恢复到最初的120高度
ValueAnimator animator = ValueAnimator.ofInt(image.getHeight(),originalHeight);
//监听动画值的变化,实现自己的动画逻辑
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int value = (int) animation.getAnimatedValue();
//我们需要将value设置给高度
ViewGroup.LayoutParams params = image.getLayoutParams();
params.height = value;
image.setLayoutParams(params);
}
});
animator.setInterpolator(new OvershootInterpolator());
animator.setDuration(500);
animator.start();
}
return super.onTouchEvent(ev);
}
}
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private ParallaxListView listview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview = (ParallaxListView) findViewById(R.id.listview);
//去掉listview滑动到头的时候边缘的蓝色阴影
listview.setOverScrollMode(AbsListView.OVER_SCROLL_NEVER);
//添加header
View header = View.inflate(this, R.layout.header, null);
ImageView image = (ImageView) header.findViewById(R.id.image);
listview.addHeaderView(header);
//设置ImageView
listview.setParallaxImage(image);
listview.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
Constant.NAMES));
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context="com.zh.parallax97.MainActivity">
<com.itheima.parallax97.ParallaxListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
仿QQ空间视差效果,ListView.setHeader( )的更多相关文章
- JS仿QQ空间鼠标停在长图片时候图片自动上下滚动效果
JS仿QQ空间鼠标停在长图片时候图片自动上下滚动效果 今天是2014年第一篇博客是关于类似于我们的qq空间长图片展示效果,因为一张很长的图片不可能全部把他展示出来,所以外层用了一个容器给他一个高度,超 ...
- 仿QQ空间长图效果简易版--母亲节感恩
手机网站 母亲节最火的两件事 1.NBA 杜兰特在获MVP催泪致辞献给母亲:她才是真的MVP. 2.QQ空间长图 ------------------------------------------- ...
- 仿QQ空间和微信朋友圈,高解耦高复用高灵活
先看看效果: 用极少的代码实现了 动态详情 及 二级评论 的 数据获取与处理 和 UI显示与交互,并且高解耦.高复用.高灵活. 动态列表界面MomentListFragment支持 下拉刷新与上拉加载 ...
- 仿QQ空间动态界面分享
先看看效果: 用极少的代码实现了 动态详情 及 二级评论 的 数据获取与处理 和 UI显示与交互,并且高解耦.高复用.高灵活. 动态列表界面MomentListFragment支持 下拉刷新与上拉加载 ...
- Fragment,仿QQ空间
转载请注明出处:http://blog.csdn.net/yangyu20121224/article/details/9023451 在今天的这篇文章当中,我依然会以实战加理论结合 ...
- iOS传感器集锦、飞机大战、开发调试工具、强制更新、Swift仿QQ空间头部等源码
iOS精选源码 飞机大作战 MUPhotoPreview -简单易用的图片浏览器 LLDebugTool是一款针对开发者和测试者的调试工具,它可以帮... 多个UIScrollView.UITable ...
- Html - 仿QQ空间右下角工具浮动块
仿QQ空间右下角工具浮动块 <style type="text/css"> .cy-tp-area>.cy-tp-fixbtn>.cy-tp-text { ...
- 仿QQ空间根据位置弹出PopupWindow显示更多操作效果
我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图: ...
- ScrollView的阻尼回弹效果实现(仿qq空间)
玩过新浪微博,qq空间等手机客户端的童鞋,都应该清楚,在主界面向下滑动时,会有一个阻尼回弹效果,看起来挺不错,接下来我们就来实现一下这种效果,下拉后回弹刷新界面,先看效果图: 这个是编辑器里面的界面效 ...
随机推荐
- Toad for Oracle的安装
分享一下Oracle 10gToad for Oracle的安装步骤 三年前用过Oracle,单纯的“用过”,主要就是说对数据库的一些操作,还不包含创建一些存储过程之类的,所以对Oracle仅仅只 ...
- 错误与修复:ASP.NET无法检测IE10,IE11,导致_doPostBack未定义JavaScript错误,恒处于F5卷动条位置
<browsers> <browser id="IE11" parentID="Mozilla"> <identifica ...
- linux 编程技术
linux 编程技术No.1前期准备工作 GCC的编译过程分为预处理.生成汇编代码.生成目标代码和链接成可执行文件等4个步骤. 使用vim编写C 文件 : [lining@localhost prog ...
- MvcMovieStore mvc5.0,EF6.01
MVC 5 实例教程(MvcMovieStore 新概念版:mvc5.0,EF6.01) - 4.创建数据上下文和数据实体模型 说明:MvcMovieStore项目已经发布上线,想了解最新版本功能请登 ...
- 大数据时代,我们为什么使用hadoop
大数据时代,我们为什么使用hadoop 我们先来看看大数据时代, 什么叫大数据,“大”,说的并不仅是数据的“多”!不能用数据到了多少TB ,多少PB 来说. 对于大数据,可以用四个词来表示:大量,多样 ...
- SolrCloud攻略
SolrCloud攻略 近期一直在使用SolrCloud,乘着酒醉大概总结一下. 1.安装 原来一直有个误区,认为SolrCloud启动时,必须至少有个core才可以,其实不然. 首先按照Solr官方 ...
- python 字符串(汉语)获得MD5编码
MD5即Message-Digest Algorithm 5(消息摘要算法第五版)的简称,是当前计算机领域用于确保信息传输完整一致而广泛使用的散列算法之一(又译哈希算法.摘要算法等),主流编程语言普遍 ...
- SP2-1503: 无法初始化 Oracle 调用界面
问题描述: win7下,cmd运行 输入sqlplus报一下错误 SP2-1503: 无法初始化 Oracle 调用界面 SP2-0152: ORACLE 不能正常工作 解决办法 1.cmd右键--以 ...
- ASP.NET MVC2.0学习笔记:路由设置
Route设置 在 <Professional in ASP.NET MVC2.0>一书的第四章,主要讲述了Route的简单设置.格式化设置.约束设置.区域路由.匹配文件.路由调试以及对R ...
- T_SQL查询语句(一): 单表查询
############################################ 查询语句--SELECT ########################################## ...