android 点击下弹动画实现
下弹动画的实现
下弹动画在很多应用都有使用,比如豌豆荚中的应用介绍界面,百度手机助手的应用介绍界面等。
只要熟悉android动画的使用接口,制作动画并不困难。 这里使用开源库nineoldandroids,其实和android3.0 以上直接使用动画接口是一样的。
实现效果
具体可以看youku动画:http://v.youku.com/v_show/id_XNjYyODgzNjQ4.html
PS, 搞了半天GIF 才能播放。原来是最大边不能太大了。原来图片尺寸太大,被默认转成jpg了。现在总算能看到效果了。
DropDownExample.java
- package com.buptfarmer.devapp;
- import com.nineoldandroids.animation.Animator;
- import com.nineoldandroids.animation.AnimatorListenerAdapter;
- import com.nineoldandroids.animation.ValueAnimator;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.ViewGroup;
- public class DropDownExample extends Activity implements OnClickListener {
- private View mHolder;
- private View mHolder2;
- // private static final int DURATION = 2000;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- initView();
- }
- private void initView() {
- setContentView(R.layout.drop_down_example);
- mHolder = findViewById(R.id.holder);
- mHolder2 = findViewById(R.id.holder2);
- mHolder.setOnClickListener(this);
- mHolder2.setOnClickListener(this);
- }
- public static ValueAnimator createHeightAnimator(final View view, int start, int end) {
- ValueAnimator animator = ValueAnimator.ofInt(start, end);
- animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
- @Override
- public void onAnimationUpdate(ValueAnimator valueAnimator) {
- int value = (Integer) valueAnimator.getAnimatedValue();
- ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
- layoutParams.height = value;
- view.setLayoutParams(layoutParams);
- }
- });
- // animator.setDuration(DURATION);
- return animator;
- }
- public static void animateExpanding(final View view) {
- view.setVisibility(View.VISIBLE);
- final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
- final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
- view.measure(widthSpec, heightSpec);
- ValueAnimator animator = createHeightAnimator(view, 0, view.getMeasuredHeight());
- animator.start();
- }
- public static void animateCollapsing(final View view) {
- int origHeight = view.getHeight();
- ValueAnimator animator = createHeightAnimator(view, origHeight, 0);
- animator.addListener(new AnimatorListenerAdapter() {
- public void onAnimationEnd(Animator animation) {
- view.setVisibility(View.GONE);
- };
- });
- animator.start();
- }
- @Override
- public void onClick(View v) {
- if (v == mHolder) {
- if (View.GONE == mHolder.findViewById(R.id.hiddenview).getVisibility()) {
- animateExpanding(mHolder.findViewById(R.id.hiddenview));
- } else {
- animateCollapsing(mHolder.findViewById(R.id.hiddenview));
- }
- } else if (v == mHolder2) {
- if (View.GONE == mHolder2.findViewById(R.id.hiddenview).getVisibility()) {
- animateExpanding(mHolder2.findViewById(R.id.hiddenview));
- } else {
- animateCollapsing(mHolder2.findViewById(R.id.hiddenview));
- }
- }
- }
- }
drop_down_example.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <LinearLayout
- android:id="@+id/holder"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:background="@color/greenyellow"
- android:orientation="vertical" >
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:orientation="horizontal"
- android:paddingLeft="1dp" >
- <ImageView
- android:id="@+id/app_icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:contentDescription="picture"
- android:minWidth="32dp"
- android:src="@drawable/ic_launcher" />
- <TextView
- android:id="@+id/app_label"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="5dp"
- android:ellipsize="end"
- android:gravity="left"
- android:singleLine="true"
- android:text="what's your dream?"
- android:textSize="13sp" />
- </LinearLayout>
- <LinearLayout
- android:id="@+id/hiddenview"
- android:layout_width="fill_parent"
- android:layout_height="40dp"
- android:gravity="center_vertical"
- android:orientation="horizontal"
- android:paddingLeft="1dp"
- android:visibility="gone" >
- <TextView
- android:id="@+id/hidden_text"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:text="过个好年,马上有房" />
- </LinearLayout>
- </LinearLayout>
- <LinearLayout
- android:id="@+id/holder2"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:background="@color/blueviolet"
- android:orientation="vertical" >
- <LinearLayout
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:orientation="horizontal"
- android:paddingLeft="1dp" >
- <ImageView
- android:id="@+id/app_icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
- android:contentDescription="picture"
- android:minWidth="32dp"
- android:src="@drawable/ic_launcher" />
- <TextView
- android:id="@+id/app_label"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="5dp"
- android:ellipsize="end"
- android:gravity="left"
- android:singleLine="true"
- android:text="Self introduction"
- android:textSize="13sp" />
- </LinearLayout>
- <LinearLayout
- android:id="@+id/hiddenview"
- android:layout_width="fill_parent"
- android:layout_height="40dp"
- android:gravity="center_vertical"
- android:orientation="horizontal"
- android:paddingLeft="1dp"
- android:visibility="gone" >
- <ImageView
- android:contentDescription="avatar"
- android:src="@drawable/avatar"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center"/>
- <TextView
- android:id="@+id/hidden_text"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:text="乐山好事,积极乐观" />
- </LinearLayout>
- </LinearLayout>
- </LinearLayout>
android 点击下弹动画实现的更多相关文章
- android 点击edittext弹出软键盘,否则不弹
只需要加android:windowSoftInputMode="stateHidden|stateAlwaysHidden"就可以 如:<activity android: ...
- Android 使用动画效果后的控件位置处理 类似系统通知栏下拉动画
Android的动画的使用,请参考.Android的动画,在设计方面,我有点不太理解,觉得这样搞很怪,因为在控件动画后,即使设置了停留在动画结束时的位置,我们也确实看到了控件停在那个位置,但其实该控件 ...
- easyui combobox点击输入框弹出下拉框
由于easyui combobox需要点击下拉箭头才能下拉,不能像select标签那样点击输入框就下拉,所以觉得不太方便,查看了一下,combobox弹出框是一个div,原本想在他的输入框的点击事件中 ...
- Android下常见动画
摘要:Android中常见的的动画有三种:属性动画.补间动画.帧动画. 注.因为前两种内容较多,后补 一.属性动画 二.补间动画 三.帧动画:本质是将一些连贯的图片加载形成连贯的动画效果 1.在Dra ...
- Android定位&地图&导航——基于百度地图,实现自定义图标绘制并点击时弹出泡泡
一.问题描述 上一次我们使用百度地图实现基本的定位功能,接下来我们继续实现搜索和定位,并使用LocationOverlay绘制定位位置,同时展示如何使用自定义图标绘制并点击时弹出泡泡 如图所示: 二. ...
- Android PullToRrefresh 自定义下拉刷新动画 (listview、scrollview等)
PullToRefreshScrollView 自定义下拉刷新动画,只需改一处. 以下部分转载自http://blog.csdn.net/superjunjin/article/details/450 ...
- android 闹钟提醒并且在锁屏下弹出Dialog对话框并播放铃声和震动
android 闹钟提醒并且在锁屏下弹出Dialog对话框并播放铃声和震动 1.先简单设置一个闹钟提醒事件: //设置闹钟 mSetting.setOnClickListener ...
- 有序无序Ul->Li Ol->Li菜单,默认点击当前弹出下拉,再次点击收起下拉菜单(变形2 ---修饰)
从上面可以看出,两个问题,第一:下拉出现的太快太突然,第二:再点击下一个下拉菜单的时候,上一个不会闭合,针对这两个问题,接下来会一 一解决. 解决下拉太快: js中有个jquery效果,有一个效果是j ...
- 有序无序ul->li ol->li菜单,默认点击当前弹出下拉,再次点击收起下拉菜单
实现这一效果利用css和js技术结合 以ul->li为例子 <!DOCTYPE html><html lang="en"><head> & ...
随机推荐
- 12.java.lang.NoSuchMethodException
java.lang.NoSuchMethodException 方法不存在异常 当程序试图通过反射来创建对象,访问(修改或读取)某个方法,但是该方法不存在就会引发异常
- 3.java.lang.ClassNotFoundException
指定的类不存在 这里主要考虑一下类的名称和路径是否正确即可,通常都是程序试图通过字符串来加载某个类时可能引发 异常 比如: 调用Class.forName(); 或者调用ClassLoad的finaS ...
- JavaScript和php常用语法——切割字符串
在面向Web的应用中,前台和后台通信非常常用的一种格式就是字符串,所以,在通信中,我们不可避免的就需要进行字符串的拼切. 在js代码中,当我们传递一个字符串到后台代码时,我们在后台需要对字符串进行切割 ...
- poj 3323 Matrix Power Series (矩阵乘法 非递归形式)
为了搞自动机+矩阵的题目,特来学习矩阵快速幂..........非递归形式的求Sum(A+A^2+...+A^k)不是很懂,继续弄懂................不过代码简洁明了很多,亮神很给力 # ...
- poj1528---(数论)
题意:一个数除了自身以外的所有因数相加,得到的数如果小于自身,输出deficient,否则输出abundant,如果相等,输出perfect 这道题核心:求一个数的所有除本身之外的因数的和 ,i; ; ...
- Saiku如何固定查询结果table的表头和首列
在使用saiku查询的时候,当“行”和“列”的维度内容过多时,在查看时只看到数据,不知道是什么数据,维度不清楚,得来回拖动滚动条才行,所以同事提出想要固定“表头”和“首列”. 在网上找了一些现成的插件 ...
- [MOC062066]背景建模资料收集整理
一.相关博客 背景建模相关资料收集,各个链接都已给出. 资料,不可能非常完整,以后不定期更新. -----------------切割线----------------- 这个哥们总结的非常好啊,看完 ...
- 编写可维护的JS 06
7.事件处理 //典型用法 function handlerClick(event){ var popup = document.getElementById('popup'); popup.styl ...
- SQL学习之分组数据Group by
简介:"Group By"根据字面上的意思理解,就是根据"By"后面指定的规则对数据进行分组(分组就是将一个数据集按照"By"指定的规则分成 ...
- DataTable转换实体类
using System;using System.Collections.Generic;using System.Text;using System.Data;using System.Data. ...