First look at Baidu mobile assistant 5.0:
It is found that he uses customtabhost. Java to achieve the tabhost click effect at the bottom. It is very beautiful. When he clicks the tab, the text will run, and the picture will run a small animation from the bottom.
Next, I used my own method to attack his customtabhost. it seems easier to use than it!
This article only provides key code and requires the download of the project:
package com.wj.ring5577.ui;import android.os.Bundle;import android.support.v4.app.FragmentActivity;import android.view.LayoutInflater;import android.view.Menu;import android.widget.TabHost;import android.widget.TabHost.OnTabChangeListener;import com.wj.ring5577.R;public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TabHost tabHost = (TabHost) findViewById(R.id.tabhost); tabHost.setup(); // Call setup() before adding tabs if loading TabHost // using findViewById(). final WJTabMenuView mv = (WJTabMenuView) LayoutInflater.from(this) .inflate(R.layout.test, null); mv.setText("Tag A"); final WJTabMenuView mv2 = (WJTabMenuView) LayoutInflater.from(this) .inflate(R.layout.test, null); mv2.setText("Tag B"); final WJTabMenuView mv3 = (WJTabMenuView) LayoutInflater.from(this) .inflate(R.layout.test, null); mv3.setText("Tag C"); final WJTabMenuView mv4 = (WJTabMenuView) LayoutInflater.from(this) .inflate(R.layout.test, null); mv4.setText("Tag D"); tabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { mv.unSelected(); mv2.unSelected(); mv3.unSelected(); mv4.unSelected(); if (tabId.equals("taba")) { mv.selected(); } else if (tabId.equals("tabb")) { mv2.selected(); } else if (tabId.equals("tabc")) { mv3.selected(); } else if (tabId.equals("tabd")) { mv4.selected(); } } }); tabHost.addTab(tabHost.newTabSpec("taba").setIndicator(mv) .setContent(R.id.tab1)); tabHost.addTab(tabHost.newTabSpec("tabb").setIndicator(mv2) .setContent(R.id.tab2)); tabHost.addTab(tabHost.newTabSpec("tabc").setIndicator(mv3) .setContent(R.id.tab3)); tabHost.addTab(tabHost.newTabSpec("tabd").setIndicator(mv4) .setContent(R.id.tab4)); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; }}
Package COM. WJ. ring5577.ui; import android. content. context; import android. util. attributeset; import android. view. layoutinflater; import android. view. view; import android. view. animation. animation; import android. view. animation. animation. animationlistener; import android. view. animation. animationutils; import android. widget. imageview; import android. widget. linearlayout; import android. widget. textview; Import Co M. WJ. ring5577.r;/*** tab bottom menu view ** @ author Harris **/public class wjtabmenuview extends linearlayout {private textview mtextview = NULL; private imageview mimageview = NULL; private Boolean interruptflag; private context mcontext; private animation manim_txt; private animation manim_img; Public wjtabmenuview (context) {super (context); mcontext = context;} public wjtabmenuview (context c Ontext, attributeset attrs) {super (context, attrs); layoutinflater = (layoutinflater) context. getsystemservice (context. layout_inflater_service); layoutinflater. inflate (R. layout. wjtabmenulayout, this); mtextview = (textview) findviewbyid (R. id. wjtabmenu_ TV); mimageview = (imageview) findviewbyid (R. id. wjtabmenu_iv); mcontext = context; manim_txt = animationutils. loadanimation (mcontex T, R. anim. bottommenu_txt_anim); listener (New animationlistener () {@ override public void onanimationstart (animation) {}@ override public void onanimationrepeat (animation) {}@ override public void onanimationend (animation) {If (! Interruptflag) {mtextview. setvisibility (view. gone) ;}}); manim_img = animationutils. loadanimation (mcontext, R. anim. bottommenu_img_anim);} public void settext (String title) {mtextview. settext (title);}/*** discard select */Public void unselected () {interruptflag = true; clearanimation (); mtextview. setvisibility (view. visible);}/*** selected */Public void selected () {interruptflag = false; mtextview. startanimation (manim_txt); mimageview. startanimation (manim_img );}}
If you feel better, please download http://www.5577.com/5577.apk.
Source code:
Http://download.csdn.net/detail/h3c4lenovo/5992279