下载地址:https://github.com/TaurusXi/GuideBackgroundColorAnimation
使用方法如下:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <com.lgl.viewpager.ColorAnimationView android:id="@+id/ColorAnimationView" android:layout_width="match_parent" android:layout_height="match_parent" /> <android.support.v4.view.ViewPager android:id="@+id/viewPager" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="30dp" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/btn_go" android:layout_width="100dp" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="43dp" android:background="@drawable/colorbu" android:text="开始" android:visibility="gone" /> </RelativeLayout> </FrameLayout>
import android.annotation.SuppressLint; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageView; public class MainActivity extends FragmentActivity { private static final int[] resource = new int[] { R.drawable.welcome1, R.drawable.welcome4, R.drawable.welcome3, R.drawable.welcome4 }; private static final String TAG = MainActivity.class.getSimpleName(); private Button btn_go; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn_go = (Button) findViewById(R.id.btn_go); MyFragmentStatePager adpter = new MyFragmentStatePager( getSupportFragmentManager()); ColorAnimationView colorAnimationView = (ColorAnimationView) findViewById(R.id.ColorAnimationView); ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager); //设置adapter viewPager.setAdapter(adpter); //监听滑动 colorAnimationView.setmViewPager(viewPager, resource.length); colorAnimationView .setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { Log.e("TAG", "onPageScrolled"); } @Override public void onPageSelected(int position) { //Button显示或隐藏 if (position == 3) { btn_go.setVisibility(View.VISIBLE); } else { btn_go.setVisibility(View.GONE); } Log.e("TAG", "onPageSelected"); } @Override public void onPageScrollStateChanged(int state) { Log.e("TAG", "onPageScrollStateChanged"); } }); } public class MyFragmentStatePager extends FragmentStatePagerAdapter { public MyFragmentStatePager(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { return new MyFragment(position); } @Override public int getCount() { return resource.length; } } @SuppressLint("ValidFragment") public class MyFragment extends Fragment { private int position; public MyFragment(int position) { this.position = position; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ImageView imageView = new ImageView(getActivity()); imageView.setImageResource(resource[position]); return imageView; } } }