Android about implementing the sliding interface

Source: Internet
Author: User

The first thing to say is that the sliding interface, we need more than one view switch, can actually use arraylist<view> pageviews to save the view information, and then switch

Layoutinflater inflater = Getlayoutinflater ();p ageviews = new arraylist<view> ();p Ageviews.add (inflater.inflate (R.LAYOUT.ITEM01, null)); Pageviews.add (inflater.inflate (r.layout.item02, null));p Ageviews.add (inflater.inflate (r.layout.item03, null));

Then define the XML file for each ITEM01,ITEM02,ITEM03

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools ">    <linearlayout        android:id=" @+id/linearlayout1 "        android:layout_ Width= "Match_parent"        android:layout_height= "wrap_content"        android:orientation= "vertical" >        < ImageView            android:layout_width= "fill_parent"            android:layout_height= "Wrap_content"            android: background= "@drawable/feature_guide_0" >        </ImageView>    </linearlayout></linearlayout >

What I wrote on it was a simpler imageview to do an item,

It has to be said that you must define a class Guidpagechangelistener to inherit the Onpagechangelistener interface to achieve the switch between the view

public void onpageselected (int arg0) {//TODO auto-generated method stubfor (int i = 0; i < imageviews.length; i++) {IM Ageviews[arg0].setbackgroundresource (r.drawable.page_indicator_focused); if (arg0! = i) {imageviews[i]. Setbackgroundresource (R.drawable.page_indicator);}}}
An adapter Pageradapter class is also required here. We write a class of our own to inherit it.

Class Guidpageadapter extends Pageradapter

The main referenced methods are as follows

Class Guidpageadapter extends Pageradapter {@Overridepublic int getcount () {//TODO auto-generated method Stubreturn Pagev Iews.size ();} @Overridepublic boolean isviewfromobject (View arg0, Object arg1) {//TODO auto-generated method Stubreturn arg0 = arg1;} @Overridepublic void Destroyitem (View arg0, int arg1, Object arg2) {//TODO auto-generated Method Stub ((Viewpager) arg0). R Emoveview (Pageviews.get (Arg1));} @Overridepublic Object Instantiateitem (View arg0, int arg1) {//TODO auto-generated Method Stub ((Viewpager) arg0). AddView (Pageviews.get (arg1)); return Pageviews.get (ARG1);}}

This enables a simple view of the left and right sliding switch, the switch when the full screen switch, about the half-screen sliding switch back to continue

Reprint please indicate the source

http://blog.csdn.net/pishum/article/details/38024331



Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

Android about implementing the sliding interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.