viewpage 小圆点

 

<LinearLayout  
        android:id="@+id/viewGroup"  
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content"  
        android:layout_alignParentBottom="true"  
        android:layout_marginBottom="30dp"  
        android:gravity="center_horizontal"  
        android:orientation="horizontal" >  
    </LinearLayout> 

 

// group是R.layou.main中的负责包裹小圆点的LinearLayout.  
        group = (ViewGroup)main.findViewById(R.id.viewGroup);  
 
        viewPager = (ViewPager)main.findViewById(R.id.guidePages);  
 
        for (int i = 0; i < pageViews.size(); i++) {  
            imageView = new ImageView(GuideViewDemoActivity.this);  
            imageView.setLayoutParams(new LayoutParams(20,20));  
            imageView.setPadding(20, 0, 20, 0);  
            imageViews[i] = imageView;  
            if (i == 0) {  
                //默认选中第一张图片
                imageViews[i].setBackgroundResource(R.drawable.page_indicator_focused);  
            } else {  
                imageViews[i].setBackgroundResource(R.drawable.page_indicator);  
            }  
            group.addView(imageViews[i]);  
        }

 

  @Override  
        public void onPageSelected(int arg0) {  
            for (int i = 0; i < imageViews.length; i++) {  
                imageViews[arg0]  
                        .setBackgroundResource(R.drawable.page_indicator_focused);  
                if (arg0 != i) {  
                    imageViews[i]  
                            .setBackgroundResource(R.drawable.page_indicator);  
                }  
            }
 
        } 

 

 

 

 

 

<LinearLayout android:layout_width="wrap_content"
            android:layout_height="35dip"
            android:layout_gravity="bottom|center_horizontal"
            android:gravity="center" >
            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center">
                <View
                    android:id="@+id/dot01"
                    style="@style/dot_style"
                    android:background="@drawable/dot_focused"/>
                <View
                     android:id="@+id/dot02"
                    style="@style/dot_style"
                    android:layout_marginLeft="10dip"/>
                <View
                     android:id="@+id/dot03"
                    style="@style/dot_style"
                    android:layout_marginLeft="10dip"/>
                <View
                     android:id="@+id/dot04"
                     style="@style/dot_style"
                     android:layout_marginLeft="10dip"/>
        </LinearLayout>
            
        </LinearLayout>

 

dot_style.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="dot_style">
        <item name="android:layout_width">5dip</item>
        <item name="android:layout_height">5dip</item>
        <item name="android:background">@drawable/dot_normal</item>
        <item name="android:layout_marginLeft">1.5dip</item>
        <item name="android:layout_marginRight">1.5dip</item>
    </style>
</resources>

 

<?xml version="1.0" encoding="utf-8"?>  dot_focused
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    <solid android:color="#FFFFFF" />
    <corners android:radius="5dip" />
</shape>

 

<?xml version="1.0" encoding="utf-8"?>   dot_normal
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval" >
    <solid android:color="#aaFFFFFF" />
    <corners android:radius="5dip" />
</shape>

 

 

 private void initDots() {
        listDots = new ArrayList<View>();
        listDots.add(findViewById(R.id.dot01));
        listDots.add(findViewById(R.id.dot02));
        listDots.add(findViewById(R.id.dot03));
        listDots.add(findViewById(R.id.dot04));
    }

 

 

((View)listDots.get(position)).setBackgroundResource(R.drawable.dot_focused);
((View)listDots.get(oldPosition)).setBackgroundResource(R.drawable.dot_normal);

 

 

 

 

posted on 2012-08-23 16:42  jiezzy  阅读(1086)  评论(0编辑  收藏  举报