Use of the "Android UI" Slide bar

Source: Internet
Author: User

Layout file xml

side_bar_scollview.xml//Display the View container

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical">    <HorizontalscrollviewAndroid:id= "@+id/myscrollview"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent" >        <LinearLayoutAndroid:id= "@+id/ll_layout"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Horizontal" >        </LinearLayout>            </Horizontalscrollview></LinearLayout>

home.xml//the main page displayed

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Android:background= "@drawable/home_bg">    <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Home" /></LinearLayout>

menu.xml//the Menu page displayed

<?XML version= "1.0" encoding= "Utf-8"?><Framelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:background= "@drawable/menu_bg">    <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Menu" /></Framelayout>

mainactivity.java//Main activities

 PackageCom.example.side_bar_scrollview;ImportAndroid.annotation.SuppressLint;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.ViewTreeObserver.OnGlobalLayoutListener;ImportAndroid.widget.HorizontalScrollView;Importandroid.widget.LinearLayout; Public classMainactivityextendsActivity {PrivateHorizontalscrollview ScrollView; PrivateLinearLayout view_layout; Private intwidth; Private intheight; PrivateView Home_view; PrivateView Menu_view; Private floatrate=0.4f; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //Correlation Interface IDSetcontentview (R.layout.side_bar_scollview); //associated control IDscrollview=(Horizontalscrollview) Findviewbyid (R.id.myscrollview); View_layout=(LinearLayout) Findviewbyid (r.id.ll_layout); //monitoring LayoutsMylayoutlistener (); //Hide scroll barScrollview.sethorizontalscrollbarenabled (false); }    /*** Monitor Layout changes * 1.getViewTreeObserver---View Event Viewer * 2.addOnGlobalLayoutListener * When the global layout changes in a view tree or When the visual state of a view in the view tree changes, the interface class of the callback function to be called **/        Private voidMylayoutlistener () {scrollview.getviewtreeobserver (). Addongloballayoutlistener (NewOngloballayoutlistener () {@Override Public voidongloballayout () {//TODO auto-generated Method Stub//Remove the callback function for the global layout that was previously registeredview_layout.getviewtreeobserver (). Removeongloballayoutlistener ( This); //Gets the width and height of the scrollview measured by the last call to measure ()Height =scrollview.getmeasuredheight (); Width=scrollview.getmeasuredwidth (); //parsing the layout of home pages and menushome_view=getlayoutinflater (). Inflate (R.layout.home,NULL); Menu_view=getlayoutinflater (). Inflate (R.layout.menu,NULL); //add view to View_layoutView_layout.addview (Menu_view, (int) (width*Rate ), height);                            View_layout.addview (Home_view, width, height);            }        }); }}

:

Use of the "Android UI" Slide bar

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.