And a slight modification to achieve the cool sliding effect :)
The procedure is as follows:NO.1: Create a new content layout for displaying articles
<?xml version="1.0" encoding="utf-8"?><fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/right_fragment" android:name="com.example.myfragments.RightFragment" android:layout_width="match_parent" android:layout_height="match_parent"/>
No. 2: Create a menu layout for displaying menus
<?xml version="1.0" encoding="utf-8"?><fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/left_fragment" android:name="com.example.myfragments.LeftFragment" android:layout_width="match_parent" android:layout_height="match_parent"/>
No. 3: download and install SlidingMenu https://github.com/jfeinstein10/SlidingMenu open Eclipse and import SlidingMenu.
Set the properties of the project library, and select Is Library. REFERENCE The library in your own project, my project is MyFragments because sjavasingmenu comes with a android-support-v4.jar, so you need to delete the original android-support-v4.jar of your project. After successful import: OK. So far, SlidingMenu has been successfully introduced. Now let's start using it :) No. 4: To use SlidingMenu, you only need to rewrite the original MainActivity. java to the following code:
Package com. example. myfragments; import android. app. activity; import android. OS. bundle; import android. view. window; import android. view. windowManager; import com. jeremyfeinstein. slidingmenu. lib. slidingMenu; public class MainActivity extends Activity implements onItemSeletedListener {@ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); getWindow (). setFlags (Window Manager. layoutParams. FLAG_FULLSCREEN, WindowManager. layoutParams. FLAG_FULLSCREEN); requestWindowFeature (Window. FEATURE_NO_TITLE); // start to set the sliding menu setContentView (R. layout. contentlayout); // sets the display layout of the body. // actions // NO.1 inherits the SlidingActivity method // setBehindContentView (R. layout. menulayout); // set the left-side menu layout // SlidingMenu menu = getSlidingMe Nu (); // failed // No. 2 does not inherit SlidingActivity mode SlidingMenu menu = new SlidingMenu (this); menu. attachToActivity (this, SlidingMenu. SLIDING_CONTENT); menu. setMenu (R. layout. menulayout); // Add menu. setMode (SlidingMenu. LEFT); // set the menu position menu. SetTouchModeAbove (sregistringmenu. TOUCHMODE_MARGIN); // sets the menu opening mode // TOUCHMODE_FULLSCREEN full screen mode // TOUCHMODE_MARGIN edge mode // TOUCHMODE_NONE cannot open the menu by means of gestures. setShadowWidth (12); // you can specify the gradient width between the menu and the content. setShadowDrawable (R. drawable. shadow); // set the menu gradient effect menu. setFadeDegree (0.9f); // set the fade-in degree. When the menu slides out, the gradient effect fades in from 0.9 to 0. setBehindOffset (250); // set the length (dp) from the right side of the screen after the menu slides out )//------------------------------------------- Progress // set end // Fragment code addition, deletion, modification, and addition // FragmentManager fragmentmanager = getFragmentManager (); // FragmentTransaction fragmenttransaction = fragmentmanager. beginTransaction (); // LeftFragment leftfragment = new LeftFragment (); // fragmenttransaction. add (R. id. left_fragment, leftfragment); // fragmenttransaction. commit (); // Delete // FragmentManager fragmentmanager = getFragmentM Anager (); // FragmentTransaction fragmenttransaction = fragmentmanager. beginTransaction (); // Fragment leftfragment = fragmentmanager. findFragmentById (R. id. left_fragment); // fragmenttransaction. remove (leftfragment); // fragmenttransaction. commit (); // replace // FragmentManager fragmentmanager = getFragmentManager (); // FragmentTransaction fragmenttransaction = fragmentmanager. beginTransaction (); // fragmenttransacti On. replace (R. id. left_fragment, new LeftFragment (); // fragmenttransaction. commit () ;}@ Override public void onItemSeleted (int position) {RightFragment rightFragment = (RightFragment) getFragmentManager (). findFragmentById (R. id. right_fragment); if (rightFragment! = Null) rightFragment. update (position );}}
The gradient used in the above Code is set to R. drawable. shadow: for the color value used in this configuration file, see section 5 color in Android ListView SimpleAdapter 2 (including button listening in item. xml color value.
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" > <gradient android:endColor="@color/darkblue" android:centerColor="@color/darkgray" android:startColor="@color/black" /></shape>
No. 5: Sliding menu effect. Note that the gradient effect here is a gradient from black to dark gray to dark blue.
Note: Please indicate the source for reprinting. After all, the code is coded one by one ~