您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)Android使用ViewPager實(shí)現(xiàn)啟動(dòng)引導(dǎo)頁效果的案例,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
具體內(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>
關(guān)于“Android使用ViewPager實(shí)現(xiàn)啟動(dòng)引導(dǎo)頁效果的案例”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。