Android ViewSwitcher enables easy switching of views. viewswitcher

Source: Internet
Author: User

Android ViewSwitcher enables easy switching of views. viewswitcher

In the past, when using listview or gridview, if you want to add a friendly reminder when there is no content, add an imageview at the same location of the listview or gridview, then, set visibile of the control to View. visible or View. the gone method setting can also be implemented, but it is undoubtedly complicated. Now we have a better implementation method, 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" >                    <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:visibility="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>

 
Then 

dynamicViewSwitcher.setDisplayedChild(1);
To set which child view we will display. When using this control, note that ViewSwitcher can only have two subviews. Otherwise, an exception will occur, if you want to add a complex view

We can consider using layout and layout nesting.



Related Article

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.