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.