TranslateAnimation class: Position change animation class (similar to the tab switching effect)

Source: Internet
Author: User
Tags getcolor

TranslateAnimation class: Position change animation class (similar to the tab switching effect)

The TranslateAnimation class is an animated class for Android system location changes. It is used to control the location changes of View objects. This class inherits from the Animation class. Many methods in the TranslateAnimation class are consistent with the Animation class. The most common method in this class is the TranslateAnimation constructor.


[Basic syntax] public TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

Parameter description

FromXDelta: X coordinate of the starting point of the position change.

ToXDelta: X coordinate of the ending point of the location change.

FromYDelta: Y coordinate of the start point of the position change.

ToYDelta: Y coordinate of the end point of the location change.

Note: The initial coordinates are critical, especially when the animation is continuously switched. The subsequent animations take the initial coordinates as the reference system. The coordinate origin is critical.

Multiple location effects similar to tab switching can be encapsulated into the properties selected by radio, making it easier to use

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;
// Obtain the screen width,
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 );
//}
}

Coordinate Processing

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"); // number of times that Baidu searches for the local search application page
}
} 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 (Fig! = Null ){
(M_bd_BaiduHotTagFragment) Partial Fragment)
. 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 ));
}







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.