Android-ViewSwitcher example

Source: Internet
Author: User

Preface
Although ViewSwitcher's Chinese API has already been translated, it has never been used in the project, nor has it found a very simple Chinese example. Here we will discuss and share with you about its usage.
 
Statement

Related APIs
Android Chinese API (61) -- ViewSwitcher
 
Body
I. Introduction
ViewSwitcher is suitable for switching between two views with animation effects. Here we implement the switching between two views with a sliding screen effect.
 
II,
View 1
View 2
 


 
Ii. Sample Code
Switch view one and view two with animation effects.
Xml
<ViewSwitcher android: layout_alignParentBottom = "true"
Android: persistentDrawingCache = "animation" android: id = "@ + id/bottom"
Android: layout_width = "match_parent" android: inAnimation = "@ android: anim/slide_in_left"
Android: outAnimation = "@ android: anim/slide_out_right" android: layout_height = "122.0dip">
<RelativeLayout android: layout_width = "fill_parent"
Android: layout_gravity = "bottom" android: layout_marginBottom = "12.0dip"
Android: id = "@ + id/lyBottom" android: layout_height = "wrap_content">
<Button android: id = "@ + id/btn_pre" android: text = "previous"
Android: layout_width = "wrap_content" android: layout_height = "wrap_content"
Android: layout_centerVertical = "true" android: layout_toLeftOf = "@ + id/btn_middle"
Android: layout_marginRight = "1501_dip"/>
<Button android: id = "@ + id/btn_middle" android: layout_width = "wrap_content"
Android: layout_centerInParent = "true" android: onClick = "onClick" android: visibility = "invisible"
Android: textSize = "22.0sp"
Android: layout_height = "wrap_content"> </Button>
<Button android: id = "@ + id/btn_next" android: text = "Next"
Android: layout_width = "wrap_content" android: layout_height = "wrap_content"
Android: layout_centerVertical = "true" android: layout_toRightOf = "@ + id/btn_middle"
Android: layout_marginLeft = "1501_dip"/>
</RelativeLayout>
<RelativeLayout android: layout_width = "fill_parent"
Android: layout_gravity = "bottom" android: layout_height = "wrap_content"
Android: orientation = "horizontal">
<ImageView android: src = "@ drawable/cube" android: id = "@ + id/btn_reinsure"
Android: layout_width = "wrap_content" android: layout_height = "wrap_content"
Android: layout_marginLeft = "1501_dip"> </ImageView>
<ImageView android: src = "@ drawable/cyddz" android: id = "@ + id/btn_identity"
Android: layout_width = "wrap_content" android: layout_height = "wrap_content"
Android: layout_toRightOf = "@ + id/btn_reinsure"
Android: layout_marginLeft = "124.0dip"> </ImageView>
<ImageView android: src = "@ drawable/cykvmce" android: id = "@ + id/btn_insure_query"
Android: layout_toRightOf = "@ + id/btn_identity" android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" android: layout_marginLeft = "1401_dip"> </ImageView>
<ImageView android: src = "@ drawable/m8gprs" android: id = "@ + id/btn_review"
Android: layout_toRightOf = "@ + id/btn_insure_query"
Android: layout_width = "wrap_content" android: layout_height = "wrap_content"
Android: layout_marginLeft = "1401_dip"> </ImageView>
<ImageView android: src = "@ drawable/th_appshareth"
Android: layout_toRightOf = "@ + id/btn_review"
Android: layout_width = "wrap_content" android: layout_height = "wrap_content"
Android: layout_marginLeft = "130.0dip"> </ImageView>
</RelativeLayout>
</ViewSwitcher>
Code Description:
1. Here we use the built-in switching effects @ android: anim/slide_in_left and @ android: anim/slide_out_right.
2. Prepare your own test images.
Java
Bottom = (ViewSwitcher) findViewById (R. id. bottom );
// Switch to the first
Bottom. setDisplayedChild (0 );
// Switch to the next
// Bottom. showNext ()

Author: "peasant uncle"

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.