使用shape图形资源制作引导页面的提示圆点

来源:互联网 发布:php手机板块 编辑:程序博客网 时间:2024/05/21 02:21

在app引导界面通常有引导界面提示小圆点,下面简单介绍一下利用shape图形资源如何实现:

本文引导界面是使用的ViewPager,当ViewPager滑动时候可以动态的改变小圆点的颜色来提示用户

1,在res文件夹下面创建子文件夹drawable,分别有两个shape图形资源,一个是默认时候,一个是选中时候

a,默认时候的shape资源:

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="oval" >    <solid android:color="@color/defalut" />    <corners android:radius="15dp"/></shape>
b,选中时候的shape资源:

<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="oval" >    <solid android:color="@color/blue" />    <corners android:radius="15dp"/></shape>

2,在xml中定义一个Linearlayout存放ImageView即小圆点

<pre name="code" class="html">        <LinearLayout            android:layout_marginTop="5dp"            android:id="@+id/ll_search"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_centerHorizontal="true"            android:orientation="horizontal" >            <ImageView                android:layout_marginLeft="5dp"                android:layout_width="15dp"                android:layout_height="15dp"                android:background="@drawable/guide_dot_select" />            <ImageView                android:layout_marginLeft="5dp"                android:layout_width="15dp"                android:layout_height="15dp"                android:background="@drawable/guide_dot_nomal" />            <ImageView                android:layout_marginLeft="5dp"                android:layout_width="15dp"                android:layout_height="15dp"                android:background="@drawable/guide_dot_nomal" />            <ImageView                android:layout_marginLeft="5dp"                android:layout_width="15dp"                android:layout_height="15dp"                android:background="@drawable/guide_dot_nomal" />        </LinearLayout>


3,代码中实现:ViewPager滑动时候改变圆点颜色
mViewPager.addOnPageChangeListener(new OnPageChangeListener() {@Overridepublic void onPageSelected(int position) {// TODO Auto-generated method stubfor (int i = 0; i < ll_search.getChildCount(); i++) {if (i == position) {ll_search.getChildAt(i).setBackgroundResource(R.drawable.guide_dot_select);} else {ll_search.getChildAt(i).setBackgroundResource(R.drawable.guide_dot_nomal);}}}@Overridepublic void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {// TODO Auto-generated method stub}@Overridepublic void onPageScrollStateChanged(int state) {// TODO Auto-generated method stub}});



1 0
原创粉丝点击