• ViewPager渲染背景颜色渐变(引导页)--第三方开源--ColorAnimationView


    下载地址: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;
            }
        }
    }
  • 相关阅读:
    ECS内网穿透
    设置服务器ssh会话时间
    VScode插件
    Linux拷贝U盘文件(命令行)
    打开IDM下载视频时弹出防火墙阻止下载,解决方案
    如何将jmeter.bat命令文件固定到任务栏
    jmeter安装教程
    安装JDK8.0(JDK1.8) & 环境变量配置 & idea中配置java路径
    教你不用任何第三方软件实现任务栏居中
    [Unity优化]gc03:代码优化
  • 原文地址:https://www.cnblogs.com/zzw1994/p/5198502.html
Copyright © 2020-2023  润新知