下弹动画的实现

下弹动画在很多应用都有使用,比如豌豆荚中的应用介绍界面,百度手机助手的应用介绍界面等。

只要熟悉android动画的使用接口,制作动画并不困难。 这里使用开源库nineoldandroids,其实和android3.0 以上直接使用动画接口是一样的。

实现效果

具体可以看youku动画:http://v.youku.com/v_show/id_XNjYyODgzNjQ4.html

PS, 搞了半天GIF 才能播放。原来是最大边不能太大了。原来图片尺寸太大,被默认转成jpg了。现在总算能看到效果了。

DropDownExample.java

  1. package com.buptfarmer.devapp;
  2. import com.nineoldandroids.animation.Animator;
  3. import com.nineoldandroids.animation.AnimatorListenerAdapter;
  4. import com.nineoldandroids.animation.ValueAnimator;
  5. import android.app.Activity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.view.View.OnClickListener;
  9. import android.view.ViewGroup;
  10. public class DropDownExample extends Activity implements OnClickListener {
  11. private View mHolder;
  12. private View mHolder2;
  13. //    private static final int DURATION = 2000;
  14. @Override
  15. protected void onCreate(Bundle savedInstanceState) {
  16. super.onCreate(savedInstanceState);
  17. initView();
  18. }
  19. private void initView() {
  20. setContentView(R.layout.drop_down_example);
  21. mHolder = findViewById(R.id.holder);
  22. mHolder2 = findViewById(R.id.holder2);
  23. mHolder.setOnClickListener(this);
  24. mHolder2.setOnClickListener(this);
  25. }
  26. public static ValueAnimator createHeightAnimator(final View view, int start, int end) {
  27. ValueAnimator animator = ValueAnimator.ofInt(start, end);
  28. animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  29. @Override
  30. public void onAnimationUpdate(ValueAnimator valueAnimator) {
  31. int value = (Integer) valueAnimator.getAnimatedValue();
  32. ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
  33. layoutParams.height = value;
  34. view.setLayoutParams(layoutParams);
  35. }
  36. });
  37. //        animator.setDuration(DURATION);
  38. return animator;
  39. }
  40. public static void animateExpanding(final View view) {
  41. view.setVisibility(View.VISIBLE);
  42. final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
  43. final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
  44. view.measure(widthSpec, heightSpec);
  45. ValueAnimator animator = createHeightAnimator(view, 0, view.getMeasuredHeight());
  46. animator.start();
  47. }
  48. public static void animateCollapsing(final View view) {
  49. int origHeight = view.getHeight();
  50. ValueAnimator animator = createHeightAnimator(view, origHeight, 0);
  51. animator.addListener(new AnimatorListenerAdapter() {
  52. public void onAnimationEnd(Animator animation) {
  53. view.setVisibility(View.GONE);
  54. };
  55. });
  56. animator.start();
  57. }
  58. @Override
  59. public void onClick(View v) {
  60. if (v == mHolder) {
  61. if (View.GONE == mHolder.findViewById(R.id.hiddenview).getVisibility()) {
  62. animateExpanding(mHolder.findViewById(R.id.hiddenview));
  63. } else {
  64. animateCollapsing(mHolder.findViewById(R.id.hiddenview));
  65. }
  66. } else if (v == mHolder2) {
  67. if (View.GONE == mHolder2.findViewById(R.id.hiddenview).getVisibility()) {
  68. animateExpanding(mHolder2.findViewById(R.id.hiddenview));
  69. } else {
  70. animateCollapsing(mHolder2.findViewById(R.id.hiddenview));
  71. }
  72. }
  73. }
  74. }

drop_down_example.xml

    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. android:orientation="vertical" >
    6. <LinearLayout
    7. android:id="@+id/holder"
    8. android:layout_width="fill_parent"
    9. android:layout_height="wrap_content"
    10. android:background="@color/greenyellow"
    11. android:orientation="vertical" >
    12. <LinearLayout
    13. android:layout_width="fill_parent"
    14. android:layout_height="wrap_content"
    15. android:gravity="center_vertical"
    16. android:orientation="horizontal"
    17. android:paddingLeft="1dp" >
    18. <ImageView
    19. android:id="@+id/app_icon"
    20. android:layout_width="wrap_content"
    21. android:layout_height="wrap_content"
    22. android:layout_gravity="center"
    23. android:contentDescription="picture"
    24. android:minWidth="32dp"
    25. android:src="@drawable/ic_launcher" />
    26. <TextView
    27. android:id="@+id/app_label"
    28. android:layout_width="wrap_content"
    29. android:layout_height="wrap_content"
    30. android:layout_marginLeft="5dp"
    31. android:ellipsize="end"
    32. android:gravity="left"
    33. android:singleLine="true"
    34. android:text="what's your dream?"
    35. android:textSize="13sp" />
    36. </LinearLayout>
    37. <LinearLayout
    38. android:id="@+id/hiddenview"
    39. android:layout_width="fill_parent"
    40. android:layout_height="40dp"
    41. android:gravity="center_vertical"
    42. android:orientation="horizontal"
    43. android:paddingLeft="1dp"
    44. android:visibility="gone" >
    45. <TextView
    46. android:id="@+id/hidden_text"
    47. android:layout_width="wrap_content"
    48. android:layout_height="fill_parent"
    49. android:text="过个好年,马上有房" />
    50. </LinearLayout>
    51. </LinearLayout>
    52. <LinearLayout
    53. android:id="@+id/holder2"
    54. android:layout_width="fill_parent"
    55. android:layout_height="wrap_content"
    56. android:background="@color/blueviolet"
    57. android:orientation="vertical" >
    58. <LinearLayout
    59. android:layout_width="fill_parent"
    60. android:layout_height="wrap_content"
    61. android:gravity="center_vertical"
    62. android:orientation="horizontal"
    63. android:paddingLeft="1dp" >
    64. <ImageView
    65. android:id="@+id/app_icon"
    66. android:layout_width="wrap_content"
    67. android:layout_height="wrap_content"
    68. android:layout_gravity="center"
    69. android:contentDescription="picture"
    70. android:minWidth="32dp"
    71. android:src="@drawable/ic_launcher" />
    72. <TextView
    73. android:id="@+id/app_label"
    74. android:layout_width="wrap_content"
    75. android:layout_height="wrap_content"
    76. android:layout_marginLeft="5dp"
    77. android:ellipsize="end"
    78. android:gravity="left"
    79. android:singleLine="true"
    80. android:text="Self introduction"
    81. android:textSize="13sp" />
    82. </LinearLayout>
    83. <LinearLayout
    84. android:id="@+id/hiddenview"
    85. android:layout_width="fill_parent"
    86. android:layout_height="40dp"
    87. android:gravity="center_vertical"
    88. android:orientation="horizontal"
    89. android:paddingLeft="1dp"
    90. android:visibility="gone" >
    91. <ImageView
    92. android:contentDescription="avatar"
    93. android:src="@drawable/avatar"
    94. android:layout_width="wrap_content"
    95. android:layout_height="wrap_content"
    96. android:layout_gravity="center"/>
    97. <TextView
    98. android:id="@+id/hidden_text"
    99. android:layout_width="wrap_content"
    100. android:layout_height="fill_parent"
    101. android:text="乐山好事,积极乐观" />
    102. </LinearLayout>
    103. </LinearLayout>
    104. </LinearLayout>

android 点击下弹动画实现的更多相关文章

  1. android 点击edittext弹出软键盘,否则不弹

    只需要加android:windowSoftInputMode="stateHidden|stateAlwaysHidden"就可以 如:<activity android: ...

  2. Android 使用动画效果后的控件位置处理 类似系统通知栏下拉动画

    Android的动画的使用,请参考.Android的动画,在设计方面,我有点不太理解,觉得这样搞很怪,因为在控件动画后,即使设置了停留在动画结束时的位置,我们也确实看到了控件停在那个位置,但其实该控件 ...

  3. easyui combobox点击输入框弹出下拉框

    由于easyui combobox需要点击下拉箭头才能下拉,不能像select标签那样点击输入框就下拉,所以觉得不太方便,查看了一下,combobox弹出框是一个div,原本想在他的输入框的点击事件中 ...

  4. Android下常见动画

    摘要:Android中常见的的动画有三种:属性动画.补间动画.帧动画. 注.因为前两种内容较多,后补 一.属性动画 二.补间动画 三.帧动画:本质是将一些连贯的图片加载形成连贯的动画效果 1.在Dra ...

  5. Android定位&地图&导航——基于百度地图,实现自定义图标绘制并点击时弹出泡泡

    一.问题描述 上一次我们使用百度地图实现基本的定位功能,接下来我们继续实现搜索和定位,并使用LocationOverlay绘制定位位置,同时展示如何使用自定义图标绘制并点击时弹出泡泡 如图所示: 二. ...

  6. Android PullToRrefresh 自定义下拉刷新动画 (listview、scrollview等)

    PullToRefreshScrollView 自定义下拉刷新动画,只需改一处. 以下部分转载自http://blog.csdn.net/superjunjin/article/details/450 ...

  7. android 闹钟提醒并且在锁屏下弹出Dialog对话框并播放铃声和震动

    android 闹钟提醒并且在锁屏下弹出Dialog对话框并播放铃声和震动            1.先简单设置一个闹钟提醒事件: //设置闹钟 mSetting.setOnClickListener ...

  8. 有序无序Ul->Li Ol->Li菜单,默认点击当前弹出下拉,再次点击收起下拉菜单(变形2 ---修饰)

    从上面可以看出,两个问题,第一:下拉出现的太快太突然,第二:再点击下一个下拉菜单的时候,上一个不会闭合,针对这两个问题,接下来会一 一解决. 解决下拉太快: js中有个jquery效果,有一个效果是j ...

  9. 有序无序ul->li ol->li菜单,默认点击当前弹出下拉,再次点击收起下拉菜单

    实现这一效果利用css和js技术结合 以ul->li为例子 <!DOCTYPE html><html lang="en"><head> & ...

随机推荐

  1. SQL Server 输出受影响的行

    前期准备: create table Nums(X int); create table T(X int); go 目的:把对表Nums的insert | delete | update 反映到T表中 ...

  2. JavaMail学习笔记

    适逢计算机网络课程设计,本着挑战自己的态度,选择了一个从未接触的东西:邮箱客户端代理软件的设计.由于对相关协议非常陌生,只能依靠查找资料完成,在学习过程中碰到了一个非常好的博客,故向大家推荐一下. 一 ...

  3. python字符串转义与正则表达式特殊字符转义

    最近在自学python,字符串和正则表达式的特殊字符转义有点混淆,做个笔记简单总结一下. 1.普通字符串转义 在字符串中使用特殊字符时,要用反斜杠(\)转义字符.例如:'Let\'s go!',这里对 ...

  4. schema文件中cube的事实表使用视图方法

    在cube中可以使用查询结果或者视图来当做事实表,其中view的alias相当于表名,这个要和同一个cube中的level的表名对应,代码如下: <Cube name="YHZXZLF ...

  5. 数学之路-python计算实战(13)-机器视觉-图像增强

    指数变换的基本表达式为:y=bc(x-a)-1 当中參数b.c控制曲线的变换形状,參数a控制曲线的位置. 指数变换的作用是扩展图像的高灰度级.压缩低灰度级.能够用于亮度过高的图像 本博客全部内容是原创 ...

  6. .net网站开发(前端):4.MVC HtmlHelper

    通过前面三节,已经大概理解MVC是怎样运作的了.MVC的一个特点就是可以很方便地控制视图效果,数据交互也很灵活.先讲一下视图控制的,HtmlHelper,看到Help就知道它是不知疲惫的好人啦(有点像 ...

  7. 【DateStructure】 Charnming usages of Map collection in Java

    When learning the usage of map collection in java, I found serveral beneficial methods that was enco ...

  8. asp.net MVC Razor 语法(3)

    编程逻辑:执行基于条件的代码. If 条件 C# 允许您执行基于条件的代码. 如需测试某个条件,您可以使用 if 语句.if 语句会基于您的测试来返回 true 或 false: if 语句启动代码块 ...

  9. C++中常用特殊符号简介(& , * , : , :: , ->)

    1."&"一般表示:引用,按位与,取地址. 如: class Complex { public: Complex operator+(Complex &c2) .. ...

  10. iOS iOS9下修改回HTTP模式进行网络请求

    升级为iOS9后,默认请求类型为https,如何使用http进行请求会报错 The resource could not be loaded because the App Transport Sec ...