TranslateAnimation类:位置变化动画类 (类似tab切换效果)

TranslateAnimation类是Android系统中的位置变化动画类,用于控制View对象的位置变化,该类继承于Animation类。TranslateAnimation类中的很多方法都与Animation类一致,该类中最常用的方法便是TranslateAnimation构造方法。

【基本语法】public TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

参数说明

fromXDelta:位置变化的起始点X坐标。

toXDelta:位置变化的结束点X坐标。

fromYDelta:位置变化的起始点Y坐标。

toYDelta:位置变化的结束点Y坐标。

注意:特别是动画连续切换的时候,初始坐标很关键,后续动画都以初始坐标为参考系切记,坐标原点很关键

多个类似tab 切换的位置效果,本来可以封装成radio 选择的性质,使用起来会更方便

private void InitWidth() {

ivBottomLine = (ImageView) findViewById(R.id.iv_bottom_line);

bottomLineWidth = ivBottomLine.getLayoutParams().width;

DisplayMetrics dm = new DisplayMetrics();

getWindowManager().getDefaultDisplay().getMetrics(dm);

int screenW = dm.widthPixels;

position_one = (int) (screenW / 3.0);

position_two = position_one * 2;

position_three = position_one * 3;

// 获取屏幕宽度,

Display displaey = StaticMethod.getDisplay(this);

int width = (displaey.getWidth() / 3);

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(

width, LayoutParams.FILL_PARENT);

int kk = width*2;

switch (type) {

case FROM_LAUNCHER_GONGBIAO_SEARCH:

// mPager.setCurrentItem(1);

layoutParams.setMargins(0, 0, 0, 0);

break;

case FROM_LAUNCHER_GONGLIST_SEARCH:

// mPager.setCurrentItem(1);

layoutParams.setMargins(kk, 0, 0, 0);

break;

default:

layoutParams.setMargins(width, 0, 0, 0);

break;

}

// layoutParams.setMargins(width, 0, 0, 0);

ivBottomLine.setLayoutParams(layoutParams);

// String model = Build.MODEL;

// String mmodel = null;

// try {

// mmodel = URLEncoder.encode(model, "utf-8");

// } catch (UnsupportedEncodingException e) {

// e.printStackTrace();

// } catch (Exception e) {

// }

// if (mmodel != null && mmodel.equals("GT-N5100")) {

// LinearLayout.LayoutParams txt_params1 = new

// LinearLayout.LayoutParams(190,36);

// txt_params1.setMargins(106, 0, 0, 0);

// ivBottomLine.setLayoutParams(txt_params1);

// }

}

坐标处理

public class MyOnPageChangeListener implements OnPageChangeListener {

@Override

public void onPageSelected(int arg0) {

Animation animation = null;

Display displaey = A_StaticMethod

.getDisplay(BaiduSearchActivity.this);

int width = displaey.getWidth() / 3;

switch (arg0) {

case 0:

if (currIndex == 1) {

switch (type) {

case FROM_LAUNCHER_GONGBIAO_SEARCH:

animation = new TranslateAnimation(position_one,

0, 0, 0);

break;

case FROM_LAUNCHER_GONGLIST_SEARCH:

Log.i("xx", "k===dsds=====currIndex========"+currIndex);

animation = new TranslateAnimation(-position_one, -position_two, 0, 0);

break;

default:

animation = new TranslateAnimation(position_one,

-width, 0, 0);

break;

}

tvTabHotKey

.setTextColor(resources

.getColor(R.color.m_bd_baidu_search_tab_normal_textc));

} else if (currIndex == 2) {

switch (type) {

case FROM_LAUNCHER_GONGBIAO_SEARCH:

animation = new TranslateAnimation(position_two,

0, 0, 0);

break;

case FROM_LAUNCHER_GONGLIST_SEARCH:

animation = new TranslateAnimation(0,

-position_two, 0, 0);

break;

default:

animation = new TranslateAnimation(position_two, -width, 0,

0);

break;

}

tvTabApp.setTextColor(resources

.getColor(R.color.m_bd_baidu_search_tab_normal_textc));

}

tvTabLocal.setTextColor(resources

.getColor(R.color.m_bd_baidu_search_tab_select_textc));

boolean conStatus = StaticMethod

.getNetworkConnectionStatus(BaiduSearchActivity.this);

String completeText = editText.getText().toString();

completeText = A_StaticMethod.StringFilterByRegEx(completeText);

try {

if (localFragment != null) {

((M_bd_SearchLocalFragment) localFragment)

.initData(completeText);

MobclickAgent

.onEvent(BaiduSearchActivity.this,

"BaiduSearchActivity_widget_localsearch_app_420");// 百度搜索本地搜索应用页点击搜索的次数

}

} catch (Exception e) {

}

downManager.setVisibility(View.GONE);

downloadNotInstallLayout.setVisibility(View.GONE);

titleIcon.setImageDrawable(getResources().getDrawable(

R.drawable.m_bd_baidu_search_page2icon_bg));

editText.setHint(getResources().getString(

R.string.a_appstore_search_hint));

closeIme();

break;

case 1:

if (currIndex == 0) {

switch (type) {

case FROM_LAUNCHER_GONGBIAO_SEARCH:

animation = new TranslateAnimation(0, position_one, 0,

0);

break;

case FROM_LAUNCHER_GONGLIST_SEARCH:

animation = new TranslateAnimation(-position_two,

-position_one, 0, 0);

break;

default:

animation = new TranslateAnimation(0, position_one

- width, 0, 0);

break;

}

tvTabLocal

.setTextColor(resources

.getColor(R.color.m_bd_baidu_search_tab_normal_textc));

} else if (currIndex == 2) {

switch (type) {

case FROM_LAUNCHER_GONGBIAO_SEARCH:

animation = new TranslateAnimation(position_two,

position_one, 0, 0);

break;

case FROM_LAUNCHER_GONGLIST_SEARCH:

animation = new TranslateAnimation(0,

-position_one, 0, 0);

break;

default:

animation = new TranslateAnimation(position_two,

position_one - width, 0, 0);

break;

}

tvTabApp.setTextColor(resources

.getColor(R.color.m_bd_baidu_search_tab_normal_textc));

}

tvTabHotKey.setTextColor(resources

.getColor(R.color.m_bd_baidu_search_tab_select_textc));

conStatus = StaticMethod

.getNetworkConnectionStatus(BaiduSearchActivity.this);

if (conStatus) {

completeText = editText.getText().toString();

completeText = A_StaticMethod

.StringFilterByRegEx(completeText);

if (appsFragment != null) {

((M_bd_BaiduHotTagFragment) appsFragment)

.initHint(completeText);

}

} else {

Toast.makeText(BaiduSearchActivity.this,

getString(R.string.M_bd_net_set),

Toast.LENGTH_SHORT).show();

}

downManager.setVisibility(View.GONE);

downloadNotInstallLayout.setVisibility(View.GONE);

titleIcon.setImageDrawable(getResources().getDrawable(

R.drawable.widget_baidu_activity_logo));

editText.setHint(getResources().getString(

R.string.baidusb_widget_search_hint));

closeIme();

break;

case 2:

if (currIndex == 0) {

Log.i("xx", "k========currIndex========"+currIndex);

switch (type) {

case FROM_LAUNCHER_GONGBIAO_SEARCH:

animation = new TranslateAnimation(0,

position_two, 0, 0);

break;

case FROM_LAUNCHER_GONGLIST_SEARCH:

animation = new TranslateAnimation(0,

0, 0, 0);

break;

default:

animation = new TranslateAnimation(0, position_two - width,

0, 0);

break;

}

tvTabLocal

.setTextColor(resources

.getColor(R.color.m_bd_baidu_search_tab_normal_textc));

} else if (currIndex == 1) {

Log.i("xx", "m========currIndex========"+currIndex);

switch (type) {

case FROM_LAUNCHER_GONGBIAO_SEARCH:

animation = new TranslateAnimation(position_one,

position_two, 0, 0);

break;

case FROM_LAUNCHER_GONGLIST_SEARCH:

animation = new TranslateAnimation(-position_one,

0, 0, 0);

break;

default:

animation = new TranslateAnimation(position_one,

position_two - width, 0, 0);

break;

}

tvTabHotKey

.setTextColor(resources

.getColor(R.color.m_bd_baidu_search_tab_normal_textc));

}

时间: 2024-10-14 14:15:50

TranslateAnimation类:位置变化动画类 (类似tab切换效果)的相关文章

CSS3 :target伪类实现Tab切换效果

用:target伪类实现Tab切换效果真的非常简单!简单到什么程度呢?它只需要下面这些代码. style.css: .song-info { position: absolute; background: #fff; } #song-info:target, #song-lyricCN:target, #song-lyricEN:target { z-index: 1; } html代码: <div class="song-nav"> <ul class="

CSS3属性之 target伪类实现Tab切换效果

CSS3 :target伪类用来改变页面中锚链接URL所指向的ID样式 代码示例: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>target伪类实现Tab切换效果</title> <style type="text/css"> p{ bond:li; } .tablis

实用CSS3属性之 :target伪类实现Tab切换效果

CSS3 :target伪类用来改变页面中锚链接URL所指向的ID样式,例如你要改变描链接指向#tab的元素字体颜色为蓝色,哪么你可以这样写成#tab:target {color:blue} 浏览器支持: 不支持IE8及以下的IE版本,IE9支持这个属性,其它非IE内核浏览器如:Firefox.Chrome.等这些浏览器都支持. 用法: :target伪类与:hover.:link.:visited.:focus等伪类的用法一样 :target {color:blue} 实例:CSS3 :tar

JavaScript - Tab切换效果

简单Tab切换效果 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&

基于jQuery图片缩放tab切换效果

基于jQuery图片缩放tab切换效果 上图: 主要效果是一个切换的效果,鼠标移动进行效果切换,兼容IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗等 预览地址:http://www.qhttl.com/content/view/2014/07/23/jiaoben92/jiaoben92/index.html 基于jQuery图片缩放tab切换效果

css实现tab切换效果

<div class="match-instruction"> <div id="tab2" class="mi-cont">奖项设置</div> <div id="tab3" class="mi-cont">评审标准</div> <div id="tab4" class="mi-cont">活动

jquery写的tab切换效果 非常简单

自己写的一款 tab切换效果,比较简单,适合新手 <style type="text/css">*{margin:0; padding:0; font-size:12px;}ul{list-style:none;}ul li a{text-decoration:none; color:#000000;}ul li a:hover{text-decoration:underline; color:#cc0000;}#con{margin:50px auto; width:96

Vue.js实现tab切换效果

利用Vue实现简易tab切换效果 1.1 在我们平时浏览网站的时候,经常看到的特效有图片轮播.导航子菜单的隐藏.tab标签的切换等等.这段时间学习了vue后,开始要写出一些简单的特效. 1.2 实现思路是点击上方的标题,下方的内容随之发生改变,上方和下方用的是两个块,是兄弟节点,所以需要点击tab标题和下方内容一一对应,基予两个模块若下标相同是一个内容实现的. 1.3 tab切换第一步先要把HTML写好,这个第一步很关键,主要分为两块结构 <div id="app"> &l

Tab切换效果(多个参数)

前几天我写了这个切换效果,但是是只传一个值的函数,经过各位大牛的指点发现还是有些问题的,于是经过我不懈的努力,完善了代码: 传递多个参数替代函数里面包含事件这个问题: html代码: 1 <div class="content"> 2 <div class="tab1 cf"> 3 <ul> 4 <li class="tab_li">第一项</li> 5 <li class=&qu