First, choose a different module, the slide will be animated form of the past, so that suitable for the news client a variety of columns display:
So write layout:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "match_parent "Android:layout_height=" match_parent "android:background=" #ffffff "> <include layout=" @layout/title_layout "/> <relativelayout android:id=" @+id/column_navi "android:layout_width=" Fill_parent "Androi d:layout_height= "Wrap_content" android:background= "@drawable/top_column_bg" > <imagebutton Android:id= "@+id/column_to_left" android:layout_width= "wrap_content" android:layout_height= "Wrap_con Tent "android:layout_alignparentleft=" true "Android:layout_centervertical=" true "Android: layout_marginleft= "5.0DP" android:background= "#00000000" android:src= "@drawable/arr_left" android:visibility= "visible"/> <imagebutton android:id= "@+id/column_to_right" Android : Layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_alignparentright= "true" Android:layout_ Centervertical= "true" android:layout_marginright= "5.0DP" android:background= "#00000000" a ndroid:src= "@drawable/arr_right" android:visibility= "visible"/>
Add data to the String.xml in the code: <string-array name= "All_choice" translatable= "false" > <item> technology </item> <item> Wealth </item> <item> Sports </item> <item> local </item> <item> latest </item> <item> baccarat </item> <item> Entertainment </item> </string-array>
private void InitTab () {string[] resource = This.getresources (). Getstringarray (R.array.all_choice); for (int j = 0; J < Resource.length; J + +) {String name = Resource[j];array.add (name);} This.columnTitleLayout.removeAllViews (); int j = This.array.size (); if (J <= 5) {this.scrollToRight.setVisibility ( view.invisible); this.scrollToLeft.setVisibility (view.invisible);} Currtabindex = 0;int i = 0;animimage.setbackgroundresource (R.drawable.slidebar); for (i = 0; i < array.size (); i++) {Str ing str = array.get (i); TextView Columntextview = new TextView (this); Columntextview.settext (str); Columntextview.settag (i); Columntextview.setpadding (18, 2, 15, 4); Columntextview.setonclicklistener (this); Columntextview.settextappearance (this, r.style.column_tx_style); Linearlayout.layoutparams params = new Linearlayout.layoutparams (layoutparams.match_parent, LayoutParams.MATCH_ PARENT); Columntitlelayout.addview (Columntextview, params);} TextView Morecolumntextview = new TextView (this); Morecolumntextview.settag (i); Charsequence localcharsequence = Getresources (). GetText (R.string.more_column); Morecolumntextview.settext (localcharsequence); Morecolumntextview.setpadding (18, 2, 15, 4); Morecolumntextview.settextappearance (this, r.style.column_tx_style); Linearlayout.layoutparams params = new Linearlayout.layoutparams (layoutparams.match_parent, LayoutParams.MATCH_ PARENT); Columntitlelayout.addview (Morecolumntextview, params);}
Start the animation when you click on the sub-column:
@Override <span style= "White-space:pre" ></span>public void OnClick (View v) {<span style= "White-space: Pre "></span>int k = (Integer) v.gettag (); <span style=" white-space:pre "></span>lasttabindex = Currtabindex;<span style= "White-space:pre" ></span>currtabindex = K;<span style= "White-space:pre" ></span>string Text = ((TextView) v). GetText (). toString (); <span style= "White-space:pre" ></span >if (Lasttabindex! = currtabindex) {<span style= "White-space:pre" ></span>if (currTabIndex = = Array.size ()) {<span style= "white-space:pre" ></span>return;<span style= "White-space:pre" ></SPAN>} <span style= "White-space:pre" ></span>showanimation (); <span style= "White-space:pre" ></span >}<span style= "White-space:pre" ></SPAN>}
Animated with Translateanimation Animation.setfillafter (true);private void ShowAnimation () {if (Lasttabindex = = Currtabindex) {return;} ((TextView) Columntitlelayout.getchildat (Lasttabindex)). SetTextColor (r.drawable.white); int widgetitemwidth = (( TextView) Columntitlelayout.getchildat (Lasttabindex)). GetWidth (); int FromX = Lasttabindex * Widgetitemwidth;int ToX = Currtabindex * WIDGETITEMWIDTH; LOG.V ("Test", "widgetitemwidth" + Widgetitemwidth + "FromX:" + FromX + "ToX:" + ToX); translateanimation animation = new Translateanimation (FromX, ToX, 0, 0); animation.setduration (500); Animation.setfillafter (True); Animation.setanimationlistener (new Animationlistener () {@Overridepublic void Onanimationstart (Animation Animation) {((TextView) Columntitlelayout.getchildat (Lasttabindex)). SetTextColor ( MainActivity.this.getResources (). GetColor (R.drawable.gray2));} @Overridepublic void Onanimationrepeat (Animation Animation) {} @Overridepublic void Onanimationend (Animation Animation {(TextView) Columntitlelayout.getchildat (Currtabindex)). SetTextColor (Mainactivity.this. Getresources (). GetColor (R.drawable.white)); lasttabindex = Currtabindex;}}); Animimage.startanimation (animation);}
The code can be downloaded in http://download.csdn.net/detail/baidu_nod/7576663
Android Title slider animation implementation (suitable for the news client various columns display)