RELATED LINKS:
Android Bottom menu Bar implementation
Recently just finished reading Viewpager, think of doing such a demo, of course, reference to the masters of the example inside the grid menu, I intend to use a custom imgbtn, but found that the pager tab in the bad layout, so it is best to select the GridView, simple and practical
First, Piontes interface XML
Activity_main.xml
Copy Code code as follows:
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:background= "@drawable/BG"
Tools:context= ". Mainactivity ">
<button
Android:id= "@+id/btn_menu"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_alignparenttop= "true"
Android:layout_centerhorizontal= "true"
android:text= "show/hide Menu"/>
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_below= "@+id/btn_menu"
android:gravity= "Center"
android:orientation= "Horizontal" >
<com.example.mymenu.myimgbtn
Android:id= "@+id/main_btn1"
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
Android:layout_margin= "15DP"
android:layout_weight= "1"/>
<com.example.mymenu.myimgbtn
Android:id= "@+id/main_btn2"
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
Android:layout_margin= "15DP"
android:layout_weight= "1"/>
<com.example.mymenu.myimgbtn
Android:id= "@+id/main_btn3"
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
Android:layout_margin= "15DP"
android:layout_weight= "1"/>
<com.example.mymenu.myimgbtn
Android:id= "@+id/main_btn4"
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
Android:layout_margin= "15DP"
android:layout_weight= "1"/>
</LinearLayout>
<relativelayout
Android:id= "@+id/layout_menu"
Android:layout_width= "Match_parent"
android:layout_height= "200DP"
Android:layout_alignparentbottom= "true" >
<linearlayout
Android:id= "@+id/menu"
Android:layout_width= "Match_parent"
android:layout_height= "40DP"
Android:background= "#dd000000"
android:gravity= "Center" >
<textview
Android:id= "@+id/tv_main"
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
android:layout_weight= "1"
android:gravity= "Center"
android:text= "Common"
Android:textcolor= "#ffffffff"/>
<textview
Android:id= "@+id/tv_utils"
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
android:layout_weight= "1"
android:gravity= "Center"
android:text= "Tools"
Android:textcolor= "#ffffffff"/>
<textview
Android:id= "@+id/tv_set"
Android:layout_width= "0DP"
android:layout_height= "Wrap_content"
android:layout_weight= "1"
android:gravity= "Center"
android:text= "Settings"
Android:textcolor= "#ffffffff"/>
</LinearLayout>
<linearlayout
Android:id= "@+id/layout_anim"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:layout_below= "@+id/menu"
android:background= "#eeff8c00" >
<imageview
Android:id= "@+id/iv_cursor"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
Android:scaletype= "Matrix"
android:src= "@drawable/img_cursor"/>
</LinearLayout>
<android.support.v4.view.viewpager
Android:id= "@+id/mypager"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@+id/layout_anim"
Android:flipinterval= "30"
android:persistentdrawingcache= "Animation"/>
</RelativeLayout>
</RelativeLayout>
three tab XML in Viewpager
View_main.xml,view_set.xml,view_utils.xml
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Android:background= "#77ff0000"
android:orientation= "Vertical" >
<gridview
Android:id= "@+id/mygridview"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Android:numcolumns= "4"
Android:layout_margin= "10DP"
Android:horizontalspacing= "20DP"
android:gravity= "Center"
Android:verticalspacing= "20DP"
></GridView>
</LinearLayout>
This is a view_main.xml, the back of the two and this is the same, no hair
And finally, there is a Girdview adapter XML
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >
<imageview
Android:id= "@+id/imgbtn_img"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_centerhorizontal= "true"
/>
<textview
Android:id= "@+id/imgbtn_text"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_below= "@+id/imgbtn_img"
Android:layout_centerhorizontal= "true"
android:text= "Text"
Android:textcolor= "#ff0000ff"
Android:textsize= "10sp"/>
</RelativeLayout>
That's the part of the XML layout.