仿微博QQ搜索框实现

大家新年快乐,过年 也不忘 学习  , 这是我过年 看到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;//整体布局

	@Override
	protected 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")
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				y = mTvSearch.getY();// 得到控件在Y轴的位置
				height = mTvSearch.getHeight();// 得到控件的高度 我没用到
				TranslateAnimation animation = new TranslateAnimation(0, 0, 0,
						-y);// 平移动画
				animation.setDuration(500);
				animation.setFillAfter(true);
				animation.setAnimationListener(new AnimationListener() {
					@Override
					public void onAnimationStart(Animation animation) {

					}

					@Override
					public void onAnimationRepeat(Animation animation) {

					}

					@Override
					public 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);
			}
		});

	}

	@Override
	protected 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);
	}
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值