Android implementation left and right swipe interface

Source: Internet
Author: User

The first thing to say is that the interface is sliding, you need multiple view to switch, you can actually use a 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));

And then define each item01,item02,item03 XML file.

<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 relatively simple imageview to make 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);}}}
We also need an adapter Pageradapter class, we write our own class to inherit it

Class Guidpageadapter extends Pageradapter

The main references are the following methods

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 allows 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



Android implementation left and right swipe 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.