u014732214的专栏

大家新年快乐,过年 也不忘 学习 , 这是我过年 看到QQ新浪微博的搜索 发现自己做的搜索框并没有 别人的那种效果 通过学习 自己简单的写了一个QQ 搜索效果 有不足和更好的解决方案请大家 提出, 话不多说下面 上代码!package com.zhl.qqsearch;import android.annotation.SuppressLint;import android.content.Intent;import android.os.Bundle;import android.support.v4.app.FragmentActivity;import android.view.View;import android.view.View.OnClickListener;import android.view.animation.Animation;import android.view.animation.TranslateAnimation;import android.view.animation.Animation.AnimationListener;import android.view.Window;import android.widget.LinearLayout;import android.widget.Toast;import android.widget.TextView;public class MainActivity extends FragmentActivity {private float y;private int height;private LinearLayout mLinear;//整体布局@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);this.requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main);mLinear = (LinearLayout) findViewById(R.id.main_realtive);final TextView mTvTitle = (TextView) findViewById(R.id.main_tv_title);final TextView mTvSearch = (TextView) findViewById(R.id.tv_search);mTvSearch.setOnClickListener(new OnClickListener() {@SuppressLint("NewApi")@Overridepublic void onClick(View v) {// TODO Auto-generated method stuby = mTvSearch.getY();// 得到控件在Y轴的位置height = mTvSearch.getHeight();// 得到控件的高度 我没用到TranslateAnimation animation = new TranslateAnimation(0, 0, 0,-y);// 平移动画animation.setDuration(500);animation.setFillAfter(true);animation.setAnimationListener(new AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationRepeat(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {Intent intent = new Intent();intent.setClass(getApplicationContext(),SearchActivity.class);startActivityForResult(intent, 100);overridePendingTransition(R.anim.animation_2,R.anim.animation_1);}});mLinear.startAnimation(animation);}});}@Overrideprotected void onActivityResult(int arg0, int arg1, Intent arg2) {// TODO Auto-generated method stub// 返回时 的 动画TranslateAnimation animation = new TranslateAnimation(0, 0, -y, 0);animation.setDuration(500);animation.setFillAfter(true);mLinear.startAnimation(animation);Toast.makeText(getApplicationContext(), "出来了", 1000).show();super.onActivityResult(arg0, arg1, arg2);}}

,忍耐力较诸脑力,尤胜一筹。

u014732214的专栏

相关文章:

你感兴趣的文章:

标签云: