Android Implementation Sidebar Slidingpanelayout

Source: Internet
Author: User
Tags spl


Main Layout 1

<?XML version= "1.0" encoding= "Utf-8"?>2 <Android.support.v4.widget.SlidingPaneLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:id= "@+id/spl"4 Xmlns:tools= "Http://schemas.android.com/tools"5 Android:layout_width= "Match_parent"6 Android:layout_height= "Match_parent"7 Tools:context= "Com.example.yzj.android_8_2.MainActivity">8 9 <FragmentTen Android:id= "@+id/fragment_left" One Android:name= "Com.example.yzj.android_8_2.LeftFragment" A Android:layout_width= "100DP" - Android:layout_height= "Match_parent"/> - the <Fragment - Android:id= "@+id/fragment_right" - Android:name= "Com.example.yzj.android_8_2.RightFragment" - Android:layout_width= "Match_parent" + Android:layout_height= "Match_parent"/> - + A </Android.support.v4.widget.SlidingPaneLayout>
//left side sidebar layout
<?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"> <ListViewAndroid:id= "@+id/lv"android:entries= "@array/website"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"></ListView></LinearLayout>
//WebView layout on the right
<?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"> <WebViewAndroid:id= "@+id/wv"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"></WebView></LinearLayout>
//Main class
Packagecom.example.yzj.android_8_2;Importandroid.support.v4.widget.SlidingPaneLayout;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;Importandroid.webkit.WebSettings;ImportAndroid.webkit.WebView;Importandroid.webkit.WebViewClient; Public classMainactivityextendsAppcompatactivityImplementsleftfragment.setwebsite{slidingpanelayout SPL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Init (); } Private voidinit () {SPL=(slidingpanelayout) Findviewbyid (R.ID.SPL); Spl.closepane (); Changewebsite ("Http://www.baidu.com")///Set the initial WebView interface for the Baidu}//override method to set the WebView display interface @Override Public voidchangewebsite (String URL) {rightfragment rf= (rightfragment) mainactivity. This. Getsupportfragmentmanager (). Findfragmentbyid (R.id.fragment_right); WebView WebView=Rf.getview (); WebSettings Settings=webview.getsettings (); Settings.setjavascriptenabled (true); Webviewclient Client=Newwebviewclient (); Webview.setwebviewclient (client); Webview.loadurl (URL); }}
 Packagecom.example.yzj.android_8_2;Importandroid.app.Activity;ImportAndroid.content.Context;ImportAndroid.os.Bundle;Importandroid.support.annotation.Nullable;Importandroid.support.v4.app.Fragment;ImportAndroid.view.LayoutInflater;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.widget.AdapterView;ImportAndroid.widget.ListView;/*** Created by YZJ on 2016/8/2.*/ Public classLeftfragmentextendsfragment{PrivateSetwebsite website; PrivateListView LV; @Nullable @Override PublicView Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {View root=inflater.inflate (R.layout.layout_left,NULL);        init (root); returnRoot; }    Private voidinit (View root) {LV=(ListView) Root.findviewbyid (r.id.lv); Lv.setonitemclicklistener (NewAdapterview.onitemclicklistener () {@Override Public voidOnitemclick (adapterview<?> paren, view view,intposition,LongID) {
Switch(position) { Case0: Website.changewebsite ("Http://www.sina.com");  Break;  Case1: Website.changewebsite ("Http://www.qq.com");  Break;  Case2: Website.changewebsite ("Http://www.163.com");  Break;  Case3: Website.changewebsite ("Http://www.taobao.com");  Break;    }            }        }); } @Override Public voidOnattach (Context context) {Super. Onattach (context); Website=(setwebsite) context;//the activity down to our defined interface, note that this is a strong}//to create a callback interface, and back tune Mainactivity Public Interfacesetwebsite{ Public voidchangewebsite (String URL); }}
 Packagecom.example.yzj.android_8_2;ImportAndroid.os.Bundle;Importandroid.support.annotation.Nullable;Importandroid.support.v4.app.Fragment;ImportAndroid.view.LayoutInflater;ImportAndroid.view.View;ImportAndroid.view.ViewGroup;ImportAndroid.webkit.WebView;/*** Created by YZJ on 2016/8/2.*/ Public classRightfragmentextendsfragment{PrivateWebView WV; @Nullable @Override PublicView Oncreateview (layoutinflater inflater, ViewGroup container, Bundle savedinstancestate) {View root=inflater.inflate (R.layout.layout_right,NULL);        init (root); returnRoot; }    Private voidinit (View root) {WV=(WebView) Root.findviewbyid (R.ID.WV); }     PublicWebView GetView () {//Return to Rightfragment WebViewreturnWV; }}

The above is the Android sidebar all the code, test the success of the picture because I am the real machine debugging, will not post ...

Android Implementation Sidebar Slidingpanelayout

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.