Last active
April 13, 2016 02:56
-
-
Save joeyjiron06/6604690 to your computer and use it in GitHub Desktop.
Here is a very simple slideout menu that uses animations to show and hide a slide out menu. Slides from the left. Feel free to customize it, add to it, fork it, or whatever.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--activity_main.xml --> | |
<RelativeLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
> | |
<Button | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:id="@+id/showmenu" | |
android:text="Menu" | |
android:textColor="#ffffff" | |
android:background="#999999" | |
/> | |
<com.example.listexample.SlideoutMenu | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
android:id="@+id/slideout_menu" | |
android:layout_centerInParent="true" | |
android:background="#41DB00" | |
android:visibility="gone" | |
> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Menu" | |
android:textSize="120sp" | |
android:textColor="#ffffff" | |
android:layout_gravity="center_horizontal" | |
/> | |
<Button | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:id="@+id/hidemenu" | |
android:text="hide menu" | |
android:layout_gravity="center_horizontal" | |
/> | |
</com.example.listexample.SlideoutMenu> | |
</RelativeLayout> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//MainActvity.java | |
//shows how to use SlideoutMenu | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.util.DisplayMetrics; | |
import android.util.Log; | |
import android.view.Menu; | |
import android.view.View; | |
import android.widget.AdapterView; | |
import android.widget.Button; | |
import android.widget.LinearLayout; | |
import android.widget.ListView; | |
import java.util.ArrayList; | |
public class MainActivity extends Activity implements View.OnClickListener | |
{ | |
private SlideoutMenu slideoutMenu; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) | |
{ | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
//get width and height of window | |
DisplayMetrics metrics = new DisplayMetrics(); | |
getWindowManager().getDefaultDisplay().getMetrics(metrics); | |
slideoutMenu = (SlideoutMenu) findViewById(R.id.slideout_menu); | |
slideoutMenu.height(metrics.heightPixels); | |
slideoutMenu.width(metrics.widthPixels); | |
((Button) findViewById(R.id.showmenu)).setOnClickListener(this); | |
((Button) findViewById(R.id.hidemenu)).setOnClickListener(this); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.main, menu); | |
return true; | |
} | |
@Override | |
public void onClick(View view) | |
{ | |
switch (view.getId()) { | |
case R.id.showmenu: | |
slideoutMenu.toggle(); | |
break; | |
case R.id.hidemenu: | |
slideoutMenu.toggle(); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment