(1) tag switching interface

Source: Internet
Author: User

(1) tag switching interface

I. Code 1. Simplest: FragmentTabHost + Fragment

Http://download.csdn.net/detail/mountain3th/7630123

2. Slightly complicated: TabHost + Fragment

Http://download.csdn.net/detail/mountain3th/7630383

3. Deformation: Button + Fragment

Http://download.csdn.net/detail/mountain3th/7630181

4. upgraded version: added ViewPager to enable horizontal sliding and switching.

Http://download.csdn.net/detail/mountain3th/7630189

5. Reusable version: Inherit FragmentTabActivity and implement the abstract method.

Http://download.csdn.net/detail/mountain3th/7630355

 

Ii. Usage Analysis

1. If Fragment is used for display or simple interaction, it is the least and simplest to use the first code, but Fragment data Initialization is not allowed because it automatically calls the empty constructor of Fragment.

2. If Fragment needs to be initialized through other data, use the second or third method to redirect through replaceFragment.

3. Add viewpager if you want to have the left-right sliding Function

4. to reuse the version, you only need to implement several abstract methods to achieve tag switching, greatly saving the coding time.

 

3. layout skills

1. Classic Layout

<android.support.v4.app.FragmentTabHost        android:id="@+id/fragtab_tabhost_main"        android:layout_width="match_parent"        android:layout_height="wrap_content" /><FrameLayout        android:id="@+id/frame_container_main"        android:layout_width="match_parent"        android:layout_height="match_parent" />

2. Sliding Layout

<android.support.v4.app.FragmentTabHost        android:id="@+id/fragtab_tabhost_main"        android:layout_width="match_parent"        android:layout_height="wrap_content" >        <FrameLayout            android:id="@+id/frame_container_main"            android:layout_width="match_parent"            android:layout_height="0dp"            android:layout_weight="0" /></android.support.v4.app.FragmentTabHost><android.support.v4.view.ViewPager        android:id="@+id/vp_scroll_latestlist"        android:layout_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1" />

 

3. Another strange finding is that if the parent control layout in the Fragment layout is RelativeLayout, The EditText in the layout will remain in the previous state.


JavaScript code for tag switching (one page can be used multiple times)

Send me a source code for an email address, which is not difficult.
======================================

The tag is actually that multiple divs are located at the same position and the same size, and different divs are displayed based on the selected tag. Nothing is left. You can write it quickly, however, to be beautiful, you need to work hard.

Automatic Switch of javascript labels

<Li class = "active" name = "kpi01" onclick = "nTabs (this, 0);">
<Span> page 1 </span> </li>
<Li class = "normal" name = "kpi02" onclick = "nTabs (this, 1);">
<Span> page 2 </span> </li>
<Li class = "normal" name = "kpi03" onclick = "nTabs (this, 2);">
<Span> page 3 </span> </li>

<Script>
Var seln = "kpi01 ";
Function nTabs (thisObj, Num ){
If (thisObj. name = seln) return;
ThisObj. className = "active ";
Document. getElementByName ("seln"). className = "normal ";
Seln = thisObj. name;
}
</Script>

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.