Android slide menu implementation, android slide
It seems cool to watch a slide menu in another app, but I can't write it myself. It's sad and I hate myself. I 've been Baidu for a while, and I hate myself for not having a high level and can't understand the code. So I found many examples, but I still can't understand it. I finally got a chance, yes, I found it. This code is very simple, because it provides a class written by others, that is, the layout class, which can be directly used in XML and then can be directly run. As for what to add, just as you wish.
Well, let's not talk about it much. Now, the implementation process is really simple. A sentence is equivalent to providing an existing space. All you have to do is fill in the code in it, then you can run it. (At that time, I was looking at other people. Is it true that he used the same class? In fact, everyone is similar)
Let's take a look:
As shown in, when the menu is on the left and sliding to the right, the main interface moves to the right, and the menu slowly comes out, which is much cooler than the menu provided by Android itself.
Okay. Which class is it?
SlideHolder, which is a subclass of FrameLayout. That is to say, this is used in the XML layout file. The following code is the layout code of MainActivity:
<Span style = "font-size: 18px;"> <com. example. slidemenu_test.SlideHolder xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: id = "@ + id/holder" android: layout_width = "match_parent" android: layout_height = "match_parent" tools: context = ". mainActivity "> <ScrollView android: layout_width =" 200dp "android: layout_height =" fill_parent "android: background =" #000000 "> <LinearLayout android: layout_width =" fill_parent "android: layout_height = "fill_parent" android: orientation = "vertical"> <TextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: text = "menu 1" android: textColor = "# ffffff" android: textSize = "25sp"/> <TextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: text = "menu 2" android: textColor = "# ffffff" android: textSize = "25sp"/> </LinearLayout> </ScrollView> <LinearLayout android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: orientation = "vertical" android: background = "@ drawable/bg"> <LinearLayout android: layout_width = "fill_parent" android: layout_height = "50dp"> <ImageButton android: id = "@ + id/imageButton" android: layout_width = "50dp" android: layout_height = "50dp" android: src = "@ drawable/btn_icon" android: background = "#0000"/> </LinearLayout> </com. example. slidemenu_test.SlideHolder> </span>
Next, I will describe this code. When creating an Android project, Eclipse will automatically generate the activity_main.xml code, which is the layout file of MainActivity, we need to replace the content in activity_main.xml with the content shown above, and then we can run it directly. In the above Code, the first is ScrollView, that is, the menu. We add the content we want to the layout, and I just add a little bit for testing, next is a layout of LinearLayout. This is the main interface, that is, the interface displayed without sliding. Here, I add a button to control the menu pop-up, of course, you can run it directly without setting it. But many applications have been set, so I just set it. I added an ImageButton and set it in MainActivity, let's take a look at the MainActivity code (easy to understand ):
package com.example.slidemenu_test;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.ImageButton;public class MainActivity extends Activity {private ImageButton mBtn;private SlideHolder mSlideHolder;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mBtn = (ImageButton) findViewById(R.id.imageButton);mSlideHolder = (SlideHolder) findViewById(R.id.holder);mBtn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {mSlideHolder.toggle();}});}}In this Code, there is an ImageButton object and a SlideHolder object, add events to ImageButton, click it to bring up the menu, the menu is also relatively simple, just a line of code mSlideHolder. toggle (); function toggle is the method in SlideHolder. For more information, please download the source code.
Now, a slide menu is coming out (standing on others' shoulders, I can see more)
Source code: http://download.csdn.net/detail/programchangesworld/8589471this download