Android Viewswitcher enables easy switching of views

Source: Internet
Author: User

In the past when using the ListView or GridView, if you want to add a friendly reminder without content, it is in the same location of the ListView or GridView, add a ImageView, Then through the control of the Visibile set to View.visible or View.gone method settings, although this can also be achieved, but is undoubtedly more cumbersome, and now we have a better way to implement, that is, using Viewswitcher

The sample code is as follows:

<viewswitcher android:id= "@+id/vs_dynamic" android:layout_width= "Match_parent" android:layout_height= "155DP" android:layout_margin= "10DP" > &lt ;                        ListView android:id= "@+id/lv_dynamic" style= "@style/listviewbackground"                        Android:layout_width= "Match_parent" android:layout_height= "155DP"                        android:layout_margin= "10DP" > </ListView> <imageview                        Android:id= "@+id/iv_dynamic_nocontent" style= "@style/listviewbackground"                        Android:layout_width= "Match_parent" android:layout_height= "155DP" Android:layout_margin= "10DP" android:src= "@drawable/viewpager3" Android:vis ibility= "Visible" >                   </ImageView> </ViewSwitcher> 
Find our Viewswitcher by ID in our program

<pre name= "code" class= "java" ><pre name= "code" class= "java" ><span style= "font-family:arial, Helvetica , Sans-serif; " >viewswitcher </span><span style= "font-family:arial, Helvetica, Sans-serif;" >dynamicviewswitcher = (viewswitcher) Findviewbyid (r.id.vs_dynamic);</span>

And then through

Dynamicviewswitcher.setdisplayedchild (1);
To set which child view we are going to show, in the use of the control, it is important to note that Viewswitcher can only have two sub-views, otherwise it will be abnormal, if you want to add more complex view

We can consider using layout and nesting with layout



Android Viewswitcher enables easy switching of views

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.