Android使用ViewPager實(shí)現(xiàn)啟動(dòng)引導(dǎo)頁效果
本文實(shí)例為大家分享了Android實(shí)現(xiàn)啟動(dòng)引導(dǎo)頁效果的具體代碼,供大家參考,具體內(nèi)容如下

ViewPagerTwoActivity.java
package cn.edu.zufe.app001;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import java.util.ArrayList;
public class ViewPagerTwoActivity extends AppCompatActivity {
private int[] launchImageArray = new int[]{
R.drawable.guide_bg1,R.drawable.guide_bg2,R.drawable.guide_bg3,R.drawable.guide_bg4
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_pager_two);
ViewPager vp_launch = (ViewPager)findViewById(R.id.vp_launch);
LaunchSimpleAdapter adapter = new LaunchSimpleAdapter(this,launchImageArray);
vp_launch.setAdapter(adapter);
vp_launch.setCurrentItem(0);
}
class LaunchSimpleAdapter extends PagerAdapter{
private Context mContext;
private ArrayList<View> mViewList = new ArrayList<View>();
public LaunchSimpleAdapter(final Context context, int[] imageArray){
mContext = context;
for(int i=0; i<imageArray.length; i++){
View view = LayoutInflater.from(context).inflate(R.layout.item_launch,null);
ImageView iv_launcher = (ImageView)view.findViewById(R.id.iv_launch);
RadioGroup rg_indicate = (RadioGroup)view.findViewById(R.id.rg_indicate);
Button btn_start = (Button)view.findViewById(R.id.btn_start);
iv_launcher.setImageResource(imageArray[i]);
for(int j=0; j<imageArray.length; j++){
RadioButton radio = new RadioButton(mContext);
radio.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
radio.setButtonDrawable(R.drawable.launch_guide);
radio.setPadding(10,10,10,10);
rg_indicate.addView(radio);
}
((RadioButton)rg_indicate.getChildAt(i)).setChecked(true);
if (i == imageArray.length-1) {
btn_start.setVisibility(View.VISIBLE);
btn_start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context,"歡迎您開啟美好生活",Toast.LENGTH_SHORT).show();
}
});
}
mViewList.add(view);
}
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView(mViewList.get(position));
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
container.addView(mViewList.get(position));
return mViewList.get(position);
}
@Override
public int getCount() {
return mViewList.size();
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
return view == o;
}
}
}
activity_view_pager_two.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="cn.edu.zufe.app001.ViewPagerTwoActivity">
<androidx.viewpager.widget.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/vp_launch">
</androidx.viewpager.widget.ViewPager>
</androidx.constraintlayout.widget.ConstraintLayout>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android實(shí)現(xiàn)漸變啟動(dòng)頁和帶有指示器的引導(dǎo)頁
- android引導(dǎo)用戶開啟自啟動(dòng)權(quán)限的方法
- Android客戶端首次啟動(dòng)引導(dǎo)界面
- Android實(shí)現(xiàn)過渡動(dòng)畫、引導(dǎo)頁 Android判斷是否第一次啟動(dòng)App
- Android UI設(shè)計(jì)與開發(fā)之實(shí)現(xiàn)應(yīng)用程序只啟動(dòng)一次引導(dǎo)界面
- Android使用ViewPager實(shí)現(xiàn)啟動(dòng)引導(dǎo)頁
- Android實(shí)現(xiàn)啟動(dòng)引導(dǎo)圖
相關(guān)文章
Android實(shí)現(xiàn)帶圖標(biāo)的列表對話框
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)帶圖標(biāo)的列表對話框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12
Android studio圓形進(jìn)度條 百分?jǐn)?shù)跟隨變化
這篇文章主要為大家詳細(xì)介紹了Android studio圓形進(jìn)度條,百分號跟隨變化,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
Android中手機(jī)錄屏并轉(zhuǎn)換GIF的兩種方式
本文主要介紹了android中手機(jī)錄屏并轉(zhuǎn)換GIF的兩種方式,具有一定的參考價(jià)值,下面跟著小編一起來看下吧2017-01-01
Android?studio實(shí)現(xiàn)app登錄界面
這篇文章主要為大家詳細(xì)介紹了Android?studio實(shí)現(xiàn)app登錄界面,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
Android ListView用EditText實(shí)現(xiàn)搜索功能效果
本篇文章主要介紹了Android ListView用EditText實(shí)現(xiàn)搜索功能效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03
Android實(shí)現(xiàn)千變?nèi)f化的ViewPager切換動(dòng)畫
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)千變?nèi)f化的ViewPager切換動(dòng)畫,自定義PageTransformer實(shí)現(xiàn)個(gè)性的切換動(dòng)畫,感興趣的小伙伴們可以參考一下2016-05-05
Flutter實(shí)現(xiàn)底部導(dǎo)航欄效果
這篇文章主要為大家詳細(xì)介紹了Flutter實(shí)現(xiàn)底部導(dǎo)航欄效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08

