SoFunction
Updated on 2025-03-11

Android realizes the welcome interface effect

Nowadays, many popular software have welcome interfaces. Today I will introduce the creation of the welcome interface. Since the interface involves page sliding, ViewPager should be used. If SDK is under 4.0, it should be introduced.”This bag.

Step 1: Design, where ViewPager is a multi-page display control, where button is to display the start button on the last page, where android:visibility="invisible" is to ensure that button is not displayed on other pages, and button is only displayed on the last page. The image in the linearlayout below is a dot to display the current page status and total number of pages:

<FrameLayout xmlns:andro
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >  
    <.
        android:
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" > 
    </.>    
    <Button 
      android:text="Start Experience" 
      android:       
         android:layout_marginBottom="50dp"
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"
      android:layout_gravity="bottom|center_horizontal"
      android:visibility="invisible">
    </Button>   
    <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
         android:layout_marginBottom="30dp" 
         android:gravity="center_horizontal"     >
            
            <ImageView
             android:
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"              
          android:scaleType="matrix"
          android:src="@drawable/page_now" />
            <ImageView
             android:
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dp"              
          android:scaleType="matrix"
          android:src="@drawable/page" />
            <ImageView
             android:
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dp"                 
          android:scaleType="matrix"
          android:src="@drawable/page" />
        </LinearLayout>
        
   
</FrameLayout>

Step 2: Create MyPagerAdapter. It is easier to inherit the adapter PagerAdapter.,as follows:

package ;
 
import ;
 
import ;
import ;
import .;
import .;
import ;
import ;
import ;
import ;
public class PageviewAdapter extends PagerAdapter{
 private ArrayList<View> views;
   
 public PageviewAdapter(ArrayList<View> views){
   = views;
  
 } 
 //Page view public Object instantiateItem(View container, int position) {
  ((ViewPager)container).addView((position));
             
  return (position);
 }
  
 @Override
 public int getCount() {
  return ();
 }
 @Override
 public boolean isViewFromObject(View arg0, Object arg1) {
  return arg0 == arg1;
 }
 public void destroyItem(View container, int position, Object object) {
  ((ViewPager)container).removeView((position));
 }
 @Override
 public void finishUpdate(View arg0) {
  // TODO Auto-generated method stub
  
 }
 @Override
 public void restoreState(Parcelable arg0, ClassLoader arg1) {
  // TODO Auto-generated method stub
  
 }
 @Override
 public Parcelable saveState() {
  // TODO Auto-generated method stub
  return null;
 }
 @Override
 public void startUpdate(View arg0) {
  // TODO Auto-generated method stub
  
 }
}

Step 3: Write Activity,as follows:

package ;
 
import ;
import ;
 
import ;
 
import ;
import ;
import ;
import .;
import .;
import ;
import ;
import ;
import ;
import ;
 
public class GuideActivity extends Activity implements OnPageChangeListener{
 
 static final int PAGE_NUM = 3;//Welcome interface 3 pages in total private ArrayList<View> views;//Save the various views of the viewpager private ViewPager viewPager;
 private LayoutInflater inflater;
 private ImageView []dots; //Array of small dots 
    private Intent intent ;
    private Button startButton;
    
 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView();
        inflater = (this);  
        
        intent = new Intent(, );
        //Initialize page        initPage();
        //Initialize small dots.  .  .        initDots();
        
    }
    private void initPage(){     
                 
         views = new ArrayList<View>(); 
         
 //guide_01,guide_02, guide_03 are 3 welcome pages, add them to the views array         ((.guide_01, null));
         ((.guide_02, null));
         ((.guide_03, null));
         
         PageviewAdapter pageAdapter = new PageviewAdapter(views);
         viewPager = (ViewPager)findViewById(.guide_viewpager);
        //Binding adapter (pageAdapter);
         
         //important!  !  !  Bind pageseleted and other functions         (this);
         
           
         //Bind the start key and start using it. It can only be displayed on the last page button.         startButton = (Button)findViewById();
         
         (new  OnClickListener(){
 
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    (intent); //Jump activity    (); 
   }
         
         });
         
    }
    private void initDots(){
     dots = new ImageView[3];//Array of small dots at the bottom     //View guidePage = (View)findViewById();
     dots[0] = (ImageView) findViewById(.page0);
     dots[1] = (ImageView) findViewById(.page1);
     dots[2] = (ImageView) findViewById(.page2);
     
    }
    
 @Override
 public void onPageScrollStateChanged(int arg0) {
  // TODO Auto-generated method stub
  
 }
 @Override
 public void onPageScrolled(int arg0, float arg1, int arg2) {
  // TODO Auto-generated method stub
  
 }
 @Override
 public void onPageSelected(int arg0) {
  // TODO Auto-generated method stub
  ("the page now is " + arg0);
  
  dots[arg0].setImageDrawable(getResources().getDrawable(.page_now));
 //The selected page sets small dots as highlights, and the rest are dark dots  for (int i = 0; i < 3 ;i ++)
  {
   if (i == arg0) {continue;}
   else 
   {
    dots[i].setImageDrawable(getResources().getDrawable());
 
   }
  }
  
  //If you switch to the last page, the start button will be displayed, and the rest will be hidden  if(arg0 == PAGE_NUM -1)
  {
   ();//.setVisibility();
  }
 }
}

other:The above simply implements the welcome interface. Some blogs suggest that the button on the last page is placed in the viewpager. I tried it and it is not very useful. If the function requirements are not particularly large, the above method is quite simple.

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.