Android Typical interface design (3)--Visit NetEase News realize double navigation tab switch

Source: Internet
Author: User

First, the problem description

Double navigation tab Toggle (bottom chunk + area head navigation), implement the bottom area of the scheme using Fragmenttabhost+fragment, the area of the head navigation using Viewpager+fragment, Can be in the previous blog Android Typical interface design 2 (fragmenttabhost+fragment implementation of the bottom tab switch) based on and Android typical interface design 1 (viewpage+ Fragment implementation of the Regional Top tab sliding switch) integration application implementation. To view two blog entries, please click here: HTTP://WWW.CNBLOGS.COM/JEREHEDU/P/4607599.HTML#DXJMSJ. Effect:

Ii. main components of the case

1, first realize the bottom block tab switch, this part please refer to blog: Android Typical interface design 2 (fragmenttabhost+fragment implementation of the bottom tab switch)

2, the bottom tab corresponding to the fragment components, a total of 5 fragment for Newsfragment, Readfragment, Foundfragment, Ownerfragment, Videofragment, According to the respective design interface of different plates, the design of the Newsfragment interface is realized on the basis of the previous, the interface realizes the switch between the news channels, that is, the head navigation in the area.

First look at the newsfragment layout file:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_parent" android:layout_height= "match_parent" android:orientation= "vertical" > <relativelayout android:layout_width= "          Match_parent "android:layout_height=" wrap_content "> 

newsfragment code is as follows:

public class Newsfragment extends Fragment implements Onpagechangelistener {private View view=null;    Private Radiogroup Rgchannel=null;    Private Viewpager Viewpager;    Private Horizontalscrollview Hvchannel=null; @Override public View Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate)            {if (view==null) {view=inflater.inflate (r.layout.news_fragment_layout, NULL);            Rgchannel= (Radiogroup) View.findviewbyid (R.id.rgchannel);            Viewpager= (Viewpager) View.findviewbyid (r.id.vpnewslist);            Hvchannel= (Horizontalscrollview) View.findviewbyid (R.id.hvchannel); Rgchannel.setoncheckedchangelistener (New Radiogroup.oncheckedchangelistener () {@Overri                    De public void oncheckedchanged (radiogroup group, int checkedid) {                        Viewpager.setcurrentitem (Checkedid);        }            });                InitTab (Inflater);        Initviewpager ();        } viewgroup parent= (ViewGroup) view.getparent ();        if (parent!=null) {Parent.removeview (view);    } return view; }private list<fragment> newschannellist=new arraylist<fragment> ();p rivate NewsPageFragmentAdapter         Adapter        private void Initviewpager () {list<channel> channellist=channeldb.getselectedchannel ();            for (int i=0;i<channellist.size (); i++) {newschannelfragment fragment=new newschannelfragment ();            Bundle Bundle=new Bundle ();            Bundle.putstring ("CNAME", Channellist.get (i). GetName ());            Fragment.setarguments (bundle);        Newschannellist.add (fragment);        } adapter=new Newspagefragmentadapter (Super.getactivity (). Getsupportfragmentmanager (), newsChannelList);        Viewpager.setadapter (adapter);        Viewpager.setoffscreenpagelimit (2);        Viewpager.setcurrentitem (0); VieWpager.setonpagechangelistener (this);         } private void InitTab (Layoutinflater inflater) {list<channel> channellist=channeldb.getselectedchannel ();                    for (int i=0;i<channellist.size (); i++) {RadioButton rb= (RadioButton) inflater.            Inflate (R.LAYOUT.TAB_RB, NULL);            Rb.setid (i);            Rb.settext (Channellist.get (i). GetName ());                            Radiogroup.layoutparams params=new radiogroup.layoutparams (RadioGroup.LayoutParams.WRAP_CONTENT,            RadioGroup.LayoutParams.WRAP_CONTENT);        Rgchannel.addview (Rb,params);    } rgchannel.check (0); } @Override public void onpagescrollstatechanged (int. arg0) {} @Override public void onpagescrolled (int arg    0, float arg1, int arg2) {} @Override public void onpageselected (int idx) {settab (IDX);        } private void Settab (int idx) {RadioButton rb= (RadioButton) rgchannel.getchildat (IDX); Rb.setchecked(true);        int Left=rb.getleft ();        int Width=rb.getmeasuredwidth ();        Displaymetrics metrics=new displaymetrics ();        Super.getactivity (). Getwindowmanager (). Getdefaultdisplay (). Getmetrics (metrics);        int screenwidth=metrics.widthpixels;        int LEN=LEFT+WIDTH/2-SCREENWIDTH/2;    Hvchannel.smoothscrollto (len, 0); }}

3, Newschannelfragment   component code:

public class Newschannelfragment extends Fragment {private String channelname;    @Override public void setarguments (Bundle args) {channelname=args.getstring ("cname"); } @Override public void Onattach (activity activity) {//TODO auto-generated method stub Super.onattac    h (activity);    } private TextView view; @Override public View Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate)            {if (view==null) {view=new TextView (super.getactivity ());            View.setlayoutparams (New Layoutparams (layoutparams.match_parent,layoutparams.match_parent));            View.setgravity (Gravity.center);            View.settextsize (30);        View.settext (ChannelName);        } viewgroup parent= (ViewGroup) view.getparent ();        if (parent!=null) {Parent.removeview (view);    } return view; } @Override public void OnDestroy () {//TODO auto-generateD method Stub Super.ondestroy (); }}

To learn more about the small partners, you can click to view the source code , run the test yourself.

Inquiries or technical exchanges, please join the official QQ Group: (452379712)

Jerry Education
Source:http://blog.csdn.net/jerehedu/
This article is the copyright of Yantai Jerry Education Technology Co., Ltd. and CSDN Common, welcome reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android Typical interface design (3)--Visit NetEase News realize double navigation tab switch

Related Article

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.