本文主要是介绍高仿秘密初次安装启动引导界面,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天闲来无事,就把无秘的app给反编译了,然后简单的模仿了一下开机引导界面,废话不多说了,直接开始吧。
首先,先看一下布局文件,这里没有使用比较火的Android-ViewPagerIndicator,直接使用viewpager+四个圆圈图标来实现。布局如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:vpi="http://schemas.android.com/apk/res-auto"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="@drawable/account_guidance_bg" ><android.support.v4.view.ViewPagerandroid:id="@+id/view_pager"android:layout_width="fill_parent"android:layout_height="fill_parent" /><LinearLayoutandroid:id="@+id/layout_button"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:paddingBottom="30.0dip"android:paddingLeft="20.0dip"android:paddingRight="20.0dip" ><Buttonandroid:id="@+id/bt_register"style="?android:attr/buttonBarButtonStyle"android:layout_width="0.0dip"android:layout_height="wrap_content"android:layout_marginRight="15.0dip"android:layout_weight="1.0"android:background="@drawable/green_btn_bg"android:text="立即加入"android:textColor="@android:color/white" /><Buttonandroid:id="@+id/bt_login"style="?android:attr/buttonBarButtonStyle"android:layout_width="0.0dip"android:layout_height="wrap_content"android:layout_weight="1.0"android:background="@drawable/white_translucent_btn_bg"android:text="登录"android:textColor="@android:color/white" /></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_above="@id/layout_button"android:layout_gravity="bottom"android:layout_marginBottom="40dp"android:gravity="center"android:orientation="horizontal" ><ImageViewandroid:id="@+id/miv_01"android:layout_width="12dp"android:layout_height="12dp"android:layout_margin="4dp"android:src="@drawable/tuitional_carousel_btn" /><ImageViewandroid:id="@+id/miv_02"android:layout_width="12dp"android:layout_height="12dp"android:layout_margin="4dp"android:src="@drawable/tuitional_carousel_active_btn" /><ImageViewandroid:id="@+id/miv_03"android:layout_width="12dp"android:layout_height="12dp"android:layout_margin="4dp"android:src="@drawable/tuitional_carousel_active_btn" /><ImageViewandroid:id="@+id/miv_04"android:layout_width="12dp"android:layout_height="12dp"android:layout_margin="4dp"android:src="@drawable/tuitional_carousel_active_btn" /></LinearLayout></RelativeLayout>
下面,再来看一下activity的代码编写吧,也挺简单,初始化控件--设置监听,主要是给viewpager设置一个滑动监听,代码如下:
package com.happy.guide;import java.util.ArrayList;
import java.util.List;import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;public class MainActivity extends FragmentActivity implements OnClickListener {private ViewPager view_pager;private List<ImageView> imageViews = new ArrayList<ImageView>();private MyPagerAdapter myPagerAdapter;// 四个滑动圈private ImageView miv_01;private ImageView miv_02;private ImageView miv_03;private ImageView miv_04;private List<ImageView> circleImageViews = new ArrayList<ImageView>();private Button bt_login;private Button bt_register;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();setListener();initImageView();myPagerAdapter = new MyPagerAdapter();view_pager.setAdapter(myPagerAdapter);}/*** 初始化控件*/private void initView() {bt_register = (Button) this.findViewById(R.id.bt_register);bt_login = (Button) this.findViewById(R.id.bt_login);view_pager = (ViewPager) this.findViewById(R.id.view_pager);miv_01 = (ImageView) this.findViewById(R.id.miv_01);miv_02 = (ImageView) this.findViewById(R.id.miv_02);miv_03 = (ImageView) this.findViewById(R.id.miv_03);miv_04 = (ImageView) this.findViewById(R.id.miv_04);circleImageViews.add(miv_01);circleImageViews.add(miv_02);circleImageViews.add(miv_03);circleImageViews.add(miv_04);}/*** 设置监听*/private void setListener() {bt_login.setOnClickListener(this);bt_register.setOnClickListener(this);view_pager.setOnPageChangeListener(new OnPageChangeListener() {@Overridepublic void onPageSelected(int position) {System.out.println("当前页码:" + position);initCircleImageView();circleImageViews.get(position).setImageResource(R.drawable.tuitional_carousel_btn);}@Overridepublic void onPageScrolled(int arg0, float arg1, int arg2) {// TODO Auto-generated method stub}@Overridepublic void onPageScrollStateChanged(int arg0) {// TODO Auto-generated method stub}});}/*** 初始化小圆圈的颜色值*/protected void initCircleImageView() {miv_01.setImageResource(R.drawable.tuitional_carousel_active_btn);miv_02.setImageResource(R.drawable.tuitional_carousel_active_btn);miv_03.setImageResource(R.drawable.tuitional_carousel_active_btn);miv_04.setImageResource(R.drawable.tuitional_carousel_active_btn);}/*** 初始化四张引导图*/private void initImageView() {ImageView iv_01 = new ImageView(this);iv_01.setImageResource(R.drawable.account_guidance_0);ImageView iv_02 = new ImageView(this);iv_02.setImageResource(R.drawable.account_guidance_1);ImageView iv_03 = new ImageView(this);iv_03.setImageResource(R.drawable.account_guidance_2);ImageView iv_04 = new ImageView(this);iv_04.setImageResource(R.drawable.account_guidance_3);imageViews.add(iv_01);imageViews.add(iv_02);imageViews.add(iv_03);imageViews.add(iv_04);}private class MyPagerAdapter extends PagerAdapter {@Overridepublic int getCount() {return imageViews.size();}@Overridepublic boolean isViewFromObject(View arg0, Object arg1) {return arg0 == arg1;}@Overridepublic void destroyItem(ViewGroup container, int position, Object object) {container.removeView(imageViews.get(position));}@Overridepublic Object instantiateItem(ViewGroup container, int position) {container.addView(imageViews.get(position));return imageViews.get(position);}}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.bt_login:Toast.makeText(getApplicationContext(), "点击了登录", 0).show();break;case R.id.bt_register:Toast.makeText(getApplicationContext(), "点击了立即加入", 0).show();break;}}}
是不是挺简单呢,肯定还有比这更好的写法,简单先这么实现吧,后续再进行优化
这篇关于高仿秘密初次安装启动引导界面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!