Add a flip dot inside fragmentlayout

Source: Internet
Author: User

In a fragmentlayout inside to add a dot is actually page on the basis of completion, in fact, the point of view (view) in the fragment inside and Viewpager without the level, as if you wear a sweater, and now in your clothes on the surface of the nail a few buttons is a phenomenon. Look at the following XML code: <?xml version= "1.0" encoding= "UTF-8"?>
<framelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:id= "@+id/container"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
tools:context= "Com.newworld.dmsapp2.fragment.MainHomeFragment"
Tools:ignore= "Mergerootframe" >
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Android:layout_marginbottom= "20DP"
android:orientation= "Vertical" >


<android.support.v4.view.viewpager
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:id= "@+id/pager"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >


<!--define navigation status bar components--
<!--< Here you can use a cool picture or two dots to represent!>--
<!--
<android.support.v4.view.pagertitlestrip
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_gravity= "Top"
Android:background= "#33b5e5"
Android:textcolor= "#fff"
android:paddingtop= "4DP"
android:paddingbottom= "4DP"/>
-
</android.support.v4.view.ViewPager>
<!--
<gridview
Android:id= "@+id/home_grid"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:gravity= "Center"
Android:horizontalspacing= "20DP"
Android:numcolumns= "2"
Android:padding= "15DP"
Android:stretchmode= "ColumnWidth"
android:verticalspacing= "15DP"/>
-
</LinearLayout>
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "5DP"
Android:layout_marginbottom= "1DP"
android:orientation= "Horizontal" >
<imageview
Android:id= "@+id/down_page_num"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"/>
</LinearLayout>
</LinearLayout>
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "35dip"
android:layout_gravity= "Bottom"
android:gravity= "Center"
android:orientation= "Vertical" >
<linearlayout
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_margintop= "3dip"
android:orientation= "Horizontal" >
<view
Android:id= "@+id/dot_1"
Android:layout_width= "10dip"
android:layout_height= "10dip"
android:layout_marginleft= "2dip"
android:layout_marginright= "5dip"
android:background= "@drawable/dot_normal"/>
<view
Android:id= "@+id/dot_2"
Android:layout_width= "10dip"
android:layout_height= "10dip"
android:layout_marginleft= "5dip"
android:layout_marginright= "2dip"
android:background= "@drawable/dot_normal"/>
</LinearLayout>
</LinearLayout>
</FrameLayout> After this step, add the corresponding display and operation in Java: private void Initview (View parentview) {
resources = Getresources ();
Dots = new arraylist<view> ();
DOT1 = (View) Parentview.findviewbyid (r.id.dot_1);
Dot2 = (View) Parentview.findviewbyid (r.id.dot_2);
Dots.add (Parentview.findviewbyid (r.id.dot_1));
Dots.get (0). Setbackgroundresource (r.drawable.dot_focused);
if (config.function_page = = 1) {
Dot2.setvisibility (View.gone);
}else if (config.function_page = = 2) {
Dots.add (Parentview.findviewbyid (r.id.dot_2));
Dot2.setvisibility (view.visible);
}
Mpager = (Viewpager) Parentview.findviewbyid (R.id.pager);
Fragmentslist = new arraylist<fragment> ();
if (config.function_page = = 1) {
home1 = new Mainhomefragmentpiece ();
Fragmentslist.add (HOME1);
} else if (config.function_page = = 2) {
home1 = new Mainhomefragmentpiece ();
Fragmentslist.add (HOME1);
Home2 = new Mainhomefragmentpiecenext ();
Fragmentslist.add (home2);
}
Mpager.setadapter (New Myfragmentpageradapter (Getchildfragmentmanager (),
Fragmentslist));
Mpager.setonpagechangelistener (New Myonpagechangelistener ());
Mpager.setcurrentitem (0);
}
public class Myonpagechangelistener implements Onpagechangelistener {


@Override
public void onpageselected (int arg0) {
Animation Animation = null;
Dots.get (oldposition). Setbackgroundresource (
R.drawable.dot_normal);
Dots.get (arg0)
. Setbackgroundresource (r.drawable.dot_focused);


Oldposition = arg0;
CurrentItem = arg0;
}
@Override
public void onpagescrolled (int arg0, float arg1, int arg2) {
}


@Override
public void onpagescrollstatechanged (int arg0) {
}
}



Add a flip dot inside fragmentlayout

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.