Open Source project Slidingmenu
We're going to use an open source project Slidingmenu
is the slide menu
Go to GitHub and search for slidingmenu .
Collect More 9000 , share More
It's awesome.
Thousands of of them are awesome.
we'll download it.
If we're going to put this open source project in our own project,
then import the Module
We checked slidingmenu-master 's library .
After import, of course, will be error
We open slidingmenu 's gradle .
Modify Gradle According to the error prompt
dependencies {
Classpath ' com.android.tools.build:gradle:2.1.0 '
}
dependencies {
Compile ' com.android.support:support-v4:23.3.0 '
}
Android {
Compilesdkversion 23
Buildtoolsversion "23.0.3"
Defaultconfig {
Minsdkversion 7
Targetsdkversion 16
}
There was a mistake after the modification .
The sin method is wrong , Let's go in and see.
We found this method
float distanceinfluenceforsnapduration (float f) {
F-= 0.5f; Center the values about 0.
F *= 0.3f * math.pi/2.0f;
return (float) floatmath.sin (f);
}
Why does the sin method here have an error?
Because Floatmath is out of date , its sin method does not exist.
So we took the Float off
into Math.sin (f);
Get
and then we have to rely on this slidingmenu library .
Open Dependencies for project Structure
Add Module Dependency
Select Library_slidingmenu
Now let's use the slidingmenu Slide menu .
We go to our own project to use the slide menu Activity
like I got mainactivity inside.
We'll first change the mainactivity 's parent appcompatactivity to silidingmenu . slidingfragmentactivity
public class Mainactivity extends Slidingfragmentactivity {
}
here onCreate method of permission protected error
Because the slidingfragmentactivity is supposed to be onCreate and sealed.
So let's change the permission modifier.
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
}
and then we started setting up slidingmenu .
write a layout and then set the slide-by menu layout
Setbehindcontentview (R.layout.activity_main_menu);
get slidingmenu
Mslidingmenu = Getslidingmenu ();
set slidingmenu on the left
Mslidingmenu.setmode (Slidingmenu.left);
set how the slidingmenu is pulled out , fullscreen is all can pull out , MARGIN Just pull it out on the edge.
Mslidingmenu.settouchmodeabove (Slidingmenu.touchmode_none);
here is How much of the following main is left after the move out, my resolution is 320*480, I give a , put in Dimen.xml inside
put in the dimen.xml inside the words can be adapted to the screen , do not have to convert to convert .
Mslidingmenu.setbehindoffsetres (R.dimen.activity_main_behind_width);
basic Setup is complete.
But there's a little bit of a problem, that is, if we have the same activity background on both sides ,
Then it's hard to tell where is main, where is the menu
So we put a shadow on the edge of the menu ,
To differentiate two parts
How to do it
We write a custom pattern in drawable shadow.xml
Here's my obsessive-compulsive disorder .
If you don't want to see it, just skip it.
We're going to have a gradient color.
We have a total of 123456789abcdef in the system .
If you choose 1 and F, the middle is 8, the left side is 234567, and the right side is 9ABCDE,
If you choose 2 and E, the middle is 8, the left side is 34567, and the right side is 9ABCD. , outside is 1 and F
If you choose 3 and D, then the middle is 8, the left side is 4567, the right side is 9abc, the outside is 12 and EF
If you choose 4 and C, then the middle is 8, the left side is 567, the right side is 9ab, It's 123 and def out there.
That's it , perfect , Obsessive-Compulsive disorder .
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<gradient
Android:endcolor= "#444444"
Android:centercolor= "#88888"
Android:startcolor= "#cccccc"
/>
</shape>
and then we'll set it up for Mslidingmenu .
set the drawable of Shadow
Mslidingmenu.setshadowdrawable (R.drawable.shadow);
set The width of the shadow and see for yourself
Mslidingmenu.setshadowwidthres (R.dimen.activity_main_shadow_width);
Okay, now our slidingmenu is done.
If you want something, just go to the layout and write it.
Exhale is toggle ();
197_ Open Source Project Slidingmenu