<LinearLayout  
        android: >  
    </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:/>
        </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:andro />
</shape>

 

<?xml version="1.0" encoding="utf-8"?>   dot_normal
<shape xmlns:andro />
</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);

 

 

 

 

相关文章:

  • 2022-12-23
  • 2021-10-07
  • 2021-06-14
  • 2022-12-23
  • 2021-08-15
  • 2021-05-26
猜你喜欢
  • 2021-10-24
  • 2021-11-04
  • 2022-12-23
  • 2021-10-02
  • 2021-12-12
  • 2022-12-23
  • 2021-08-25
相关资源
相似解决方案