How to do sliding menu from right to left - android

I searching some sliding example,
but I still couldn't find for right to left sliding example.
Please can any one give sample project for sliding menu from right to left

package com.slidingmenu.example;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import com.slidingmenu.example.fragments.ColorFragment;
import com.slidingmenu.lib.SlidingMenu;
import com.slidingmenu.lib.SlidingMenu.OnClosedListener;
import com.slidingmenu.lib.SlidingMenu.OnOpenedListener;
public class LeftAndRightActivity extends BaseActivity {
public LeftAndRightActivity() {
super(R.string.left_and_right);
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSlidingMenu().setMode(SlidingMenu.LEFT_RIGHT);
getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
setContentView(R.layout.content_frame);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, new SampleListFragment())
.commit();
getSlidingMenu().setSecondaryMenu(R.layout.menu_frame_two);
getSlidingMenu().setSecondaryShadowDrawable(R.drawable.shadowright);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.menu_frame_two, new SampleListFragment())
.commit();
}
}
Make sure to get a clean and updated copy of the library as well. Just in case.

Slide menu can be done using animation classes.
Declare inside activity:
private LinearLayout slidingPanel;
private boolean isExpanded;
private DisplayMetrics metrics;
//private ListView listView;
private RelativeLayout headerPanel,menuPanel;
private int panelWidth;
private ImageView menuViewButton;
FrameLayout.LayoutParams menuPanelParameters;
FrameLayout.LayoutParams slidingPanelParameters;
LinearLayout.LayoutParams headerPanelParameters ;
LinearLayout.LayoutParams listViewParameters;
//Initialize inside oncreate
metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
panelWidth = (int) ((metrics.widthPixels)*0.45);
headerPanel = (RelativeLayout) findViewById(R.id.header);
headerPanelParameters = (LinearLayout.LayoutParams) headerPanel.getLayoutParams();
headerPanelParameters.width = metrics.widthPixels;
headerPanel.setLayoutParams(headerPanelParameters);
menuPanel = (RelativeLayout) findViewById(R.id.menuPanel);
menuPanelParameters = (FrameLayout.LayoutParams) menuPanel.getLayoutParams();
menuPanelParameters.width = panelWidth;
menuPanel.setLayoutParams(menuPanelParameters);
slidingPanel = (LinearLayout) findViewById(R.id.slidingPanel);
slidingPanelParameters = (FrameLayout.LayoutParams) slidingPanel.getLayoutParams();
slidingPanelParameters.width = metrics.widthPixels;
slidingPanel.setLayoutParams(slidingPanelParameters);
Slide the Panel:
menuViewButton = (ImageView) findViewById(R.id.menuViewButton);
menuViewButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(!isExpanded){
isExpanded = true;
//Expand
new ExpandAnimation(slidingPanel, panelWidth,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.45f, 0, 0.0f, 0, 0.0f);
//Toast.makeText(getApplicationContext(), "expand", 0).show();
}else{
isExpanded = false;
//Collapse
new CollapseAnimation(slidingPanel,panelWidth,
TranslateAnimation.RELATIVE_TO_SELF, 0.45f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f, 0, 0.0f, 0, 0.0f);
//Toast.makeText(getApplicationContext(), "Collapse", 0).show();
}
}
});
Collapse animation class:
public class CollapseAnimation extends TranslateAnimation implements TranslateAnimation.AnimationListener{
private LinearLayout slidingLayout;
int panelWidth;
public CollapseAnimation(LinearLayout layout, int width, int fromXType, float fromXValue, int toXType,
float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) {
super(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
//Initialize
slidingLayout = layout;
panelWidth = width;
setDuration(400);
setFillAfter( false );
setInterpolator(new AccelerateDecelerateInterpolator());
setAnimationListener(this);
//Clear left and right margins
LayoutParams params = (LayoutParams) slidingLayout.getLayoutParams();
params.rightMargin = 0;
params.leftMargin = 0;
slidingLayout.setLayoutParams(params);
slidingLayout.requestLayout();
slidingLayout.startAnimation(this);
//slidingLayout.setBackgroundColor();
//slidingLayout.setBackgroundColor(R.string.white);
}
#Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
}
Expand animation class:
public class ExpandAnimation extends TranslateAnimation implements Animation.AnimationListener{
private LinearLayout slidingLayout;
int panelWidth;
public ExpandAnimation(LinearLayout layout, int width, int fromXType, float fromXValue, int toXType,
float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) {
super(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
//Initialize
slidingLayout = layout;
panelWidth = width;
setDuration(400);
setFillAfter( false );
setInterpolator(new AccelerateDecelerateInterpolator());
setAnimationListener(this);
slidingLayout.startAnimation(this);
//slidingLayout.setBackgroundColor(panelWidth);
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
//Create margin and align left
LayoutParams params = (LayoutParams) slidingLayout.getLayoutParams();
params.leftMargin = panelWidth;
params.gravity = Gravity.LEFT;
slidingLayout.clearAnimation();
slidingLayout.setLayoutParams(params);
slidingLayout.requestLayout();
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
Here is the xml:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- Menu Panel -->
<RelativeLayout
android:id="#+id/menuPanel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/gray_bg"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="#+id/menu_title_1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="0dp"
android:background="#353535"
android:gravity="center_vertical"
android:paddingLeft="15dp"
android:text="#string/menu_title"
android:textColor="#android:color/white" >
</TextView>
<View
android:id="#+id/menu_item_divider_1"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_below="#+id/menu_title_1"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:background="#b5b5b5" />
<TextView
android:id="#+id/menu_item_1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/menu_item_divider_1"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:text="#string/korean" >
</TextView>
<View
android:id="#+id/menu_item_divider_2"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_below="#+id/menu_item_1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#b5b5b5" />
<TextView
android:id="#+id/menu_item_2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/menu_item_divider_2"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:text="#string/english"
>
</TextView>
<!-- Sliding Panel -->
<LinearLayout
android:id="#+id/slidingPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
android:gravity="left"
android:orientation="vertical" >
<View
android:id="#+id/dividerHeaderBottom"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#414141" />
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#color/whitec" >
<Button
android:id="#+id/buttonback"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignBottom="#+id/buttonperson"
android:layout_alignParentTop="true"
android:layout_marginRight="14dp"
android:layout_toLeftOf="#+id/buttonperson"
android:background="#drawable/back" />
<ImageView
android:id="#+id/menuViewButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginLeft="27dp"
android:layout_toRightOf="#+id/buttonyummy"
android:clickable="true"
android:contentDescription="#string/description"
android:src="#drawable/lin"
android:visibility="visible" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>

use this library.. it has right to left sliding drawer also..
in the onCreate() of the activity or wherever suitable you can use following implementation..
rightDrawer = new DrawerBuilder()
.withActivity(this)
.withDisplayBelowStatusBar(true)
.withSavedInstance(savedInstanceState)
.withDrawerGravity(Gravity.END).append(leftDrawer); // or use build() instead of append()
it will add the right to left sliding drawer...

Related

Android code hide animating button

What i need to make an animated button like this, that contains other buttons when clicked.
it begins
Begin
And transform
Clicked
We use the fabAction Library:
compile 'com.github.shell-software:fab:1.0.5'
https://github.com/shell-software/fab
Our XML is like this:
<RelativeLayout
android:id="#+id/news_item_actions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="#dimen/fab_margin"
android:layout_marginBottom="#dimen/fab_margin"
android:orientation="vertical"
android:visibility="visible"
>
<com.software.shell.fab.ActionButton
android:id="#+id/news_item_share_sms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="0dp"
app:button_color="#color/share_sms"
app:image="#drawable/share_button_sms"
/>
<com.software.shell.fab.ActionButton
android:id="#+id/news_item_share_email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="70dp"
app:button_color="#color/share_email"
app:image="#drawable/share_button_mail"
/>
<com.software.shell.fab.ActionButton
android:id="#+id/news_item_share_twitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="140dp"
app:button_color="#color/share_twitter"
app:image="#drawable/share_button_twitter"
/>
<com.software.shell.fab.ActionButton
android:id="#+id/news_item_share_facebook"
android:layout_width="36dp"
android:layout_height="36dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="210dp"
app:button_color="#color/share_facebook"
app:image="#drawable/share_button_facebook"
/>
<com.software.shell.fab.ActionButton
android:id="#+id/news_item_share_dummy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="280dp"
app:button_color="#color/share_cancel"
app:image="#drawable/share_button_cancel"
/>
</RelativeLayout>
Our java code is like this:
final ActionButton actionButton = (ActionButton) findViewById(R.id.news_item_action_button);
final ActionButton actionCancelButton = (ActionButton) findViewById(R.id.news_item_action_cancel_button);
actionButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
expand(findViewById(R.id.news_item_share_facebook), 1);
expand(findViewById(R.id.news_item_share_twitter), 2);
expand(findViewById(R.id.news_item_share_email), 3);
expand(findViewById(R.id.news_item_share_sms), 4);
actionCancelButton.setVisibility(View.VISIBLE);
actionButton.setVisibility(View.GONE);
}
});
actionCancelButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
collapse(findViewById(R.id.news_item_share_facebook), 1);
collapse(findViewById(R.id.news_item_share_twitter), 2);
collapse(findViewById(R.id.news_item_share_email), 3);
collapse(findViewById(R.id.news_item_share_sms), 4);
actionCancelButton.setVisibility(View.GONE);
actionButton.setVisibility(View.VISIBLE);
}
});
public void expand(final View v, int pos) {
v.setVisibility(View.VISIBLE);
RelativeLayout.LayoutParams paramsTemp = (RelativeLayout.LayoutParams)v.getLayoutParams();
float d = getResources().getDisplayMetrics().density;
final int expectedMove = paramsTemp.topMargin - mMargins[pos-1];//(int)((ACTION_SIZE*pos) * d);
final int[] topMargin = {paramsTemp.topMargin,mMargins[pos-1]};
Animation a = new Animation()
{
#Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)v.getLayoutParams();
if(interpolatedTime == 1){
params.setMargins(params.leftMargin, topMargin[1],params.rightMargin,params.bottomMargin);
v.setLayoutParams(params);
}else{
int addedMargin = (int)(expectedMove * interpolatedTime);
int marginTop = topMargin[0] - addedMargin;
params.setMargins(params.leftMargin, marginTop,params.rightMargin,params.bottomMargin);
v.setLayoutParams(params);
}
}
#Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setInterpolator(new DecelerateInterpolator(1.0f));
a.setDuration(750);
v.startAnimation(a);
}
/*
* This method is use to animate the collapse of share actions in this activity.
* #param (final View v) The view which will be expanded.
*/
public void collapse(final View v, int pos) {
RelativeLayout.LayoutParams paramsTemp = (RelativeLayout.LayoutParams)v.getLayoutParams();
final int[] topMargin = {paramsTemp.topMargin};
float d = getResources().getDisplayMetrics().density;
final int expectedMove = (int)((ACTION_SIZE*pos) * d);
Animation a = new Animation()
{
#Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if(interpolatedTime == 1){
v.setVisibility(View.GONE);
}else{
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)v.getLayoutParams();
int addedMargin = (int)(expectedMove * interpolatedTime);
int marginTop = topMargin[0] + addedMargin;
params.setMargins(params.leftMargin, marginTop,params.rightMargin,params.bottomMargin);
v.setLayoutParams(params);
}
}
#Override
public boolean willChangeBounds() {
return true;
}
};
// 1dp/ms
a.setInterpolator(new AccelerateInterpolator(1.0f));
a.setDuration(750);
v.startAnimation(a);
}
That is how we make the animation work. Hope it works.

Custom view is being displayed as nested views in Component Tree

I have created custom view which extends FrameLayout. After adding it into RelativeLayout it's being displayed as two nested views:
Is it normal? It sometimes messes up with wrap_content flags but I couldn't figure out why. When I use View as a base class everything looks normal.
Here is my code:
MainActivity.java
package com.example.app;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.SeekBar;
import com.codersmill.tset.R;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.example.app.RateBar
android:layout_width="match_parent"
android:layout_height="48dp"
android:id="#+id/rateBar"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
RateBar.java
package com.example.app;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.codersmill.tset.R;
public class RateBar extends FrameLayout {
TextView star1, star2, star3, star4, star5;
View dot;
private boolean isAnimating = false;
int radius = 36;
private int step = 100;
private int leftMargin = 50;
private int topMargin = 0;
private int currentPosition = 0;
public RateBar(Context context) {
this(context, null);
}
public RateBar(Context context, AttributeSet attrs) {
super(context, attrs);
View.inflate(context, R.layout.view_rate_bar, this);
star1 = (TextView) this.findViewById(R.id.star1);
star2 = (TextView) this.findViewById(R.id.star2);
star3 = (TextView) this.findViewById(R.id.star3);
star4 = (TextView) this.findViewById(R.id.star4);
star5 = (TextView) this.findViewById(R.id.star5);
star1.setOnClickListener(onClickListener);
star2.setOnClickListener(onClickListener);
star3.setOnClickListener(onClickListener);
star4.setOnClickListener(onClickListener);
star5.setOnClickListener(onClickListener);
dot = this.findViewById(R.id.selector);
}
public RateBar(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs);
}
private OnClickListener onClickListener = new OnClickListener() {
#Override public void onClick(View v) {
if(isAnimating) return;
switch (v.getId()) {
case R.id.star1:
animateToPosition(0);
break;
case R.id.star2:
animateToPosition(1);
break;
case R.id.star3:
animateToPosition(2);
break;
case R.id.star4:
animateToPosition(3);
break;
case R.id.star5:
animateToPosition(4);
break;
}
}
};
#Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
step = (int) (getMeasuredWidth() / 5.0f);
leftMargin = (int) (step / 2.0f - radius);
topMargin = (int) (getMeasuredHeight() / 2.0f - radius);
if(!isAnimating) {
FrameLayout.LayoutParams params = (LayoutParams) dot.getLayoutParams();
params.leftMargin = leftMargin + currentPosition * step;
params.topMargin = topMargin;
dot.setLayoutParams(params);
}
}
private void animateToPosition(final int position) {
final int from = currentPosition*step + leftMargin;
final int to = position*step + leftMargin;
ValueAnimator animation = ValueAnimator.ofInt(from, to);
animation.setDuration(250);
animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override public void onAnimationUpdate(ValueAnimator animation) {
FrameLayout.LayoutParams params = (LayoutParams) dot.getLayoutParams();
params.leftMargin = (int) animation.getAnimatedValue();
params.topMargin = topMargin;
dot.setLayoutParams(params);
}
});
animation.addListener(new AnimatorListenerAdapter() {
#Override public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
isAnimating = true;
FrameLayout.LayoutParams params = (LayoutParams) dot.getLayoutParams();
params.topMargin = topMargin;
params.leftMargin = currentPosition * step + leftMargin;
dot.setLayoutParams(params);
}
#Override public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
isAnimating = false;
currentPosition = position;
FrameLayout.LayoutParams params = (LayoutParams) dot.getLayoutParams();
params.leftMargin = currentPosition * step + leftMargin;
params.topMargin = topMargin;
dot.setLayoutParams(params);
}
});
animation.start();
}
private void updateDotPosition() {
}
}
view_rate_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content">
<View
android:id="#+id/selector"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="#drawable/oval"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="1"
android:id="#+id/star1"
android:layout_weight="1"
android:gravity="center"
android:padding="12dp"
android:background="#2200ff00"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="2"
android:id="#+id/star2"
android:layout_weight="1"
android:gravity="center"
android:padding="12dp"
android:background="#22ff0000"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="3"
android:id="#+id/star3"
android:layout_weight="1"
android:gravity="center"
android:padding="12dp"
android:background="#2200ff00"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="4"
android:id="#+id/star4"
android:layout_weight="1"
android:gravity="center"
android:padding="12dp"
android:background="#22ff0000"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="5"
android:id="#+id/star5"
android:layout_weight="1"
android:gravity="center"
android:padding="12dp"
android:background="#2200ff00" />
</LinearLayout>
</merge>
even i was facing the same issue, it appears that new version of android studio comes up with two files content_main.xml and activity_mail.xml , when we select Activity_main.xml>Design view everything appears 'Custom View' , instead when we highlight content_main.xml>Design, everything is bac to normal. I dont know why it happens but that;s how i fix mine ( android nooob here )
More can be found here : https://teamtreehouse.com/community/i-cant-drag-widgets-onto-the-phone-mockup-component-tree-shows-customview-instead-of-the-relative-view-help

Swiping the Fly-in sliding menu android

I'm new to programming android, I'm trying to make the effect of sliding menu with your finger, followed several tutorials over the internet but got no success, I found this library on the Internet, it works by clicking on the button, I have the same effect when sliding the finger. Thank you in advance for your help!
LayerStack.java
package com.example.slideoutmenu;
import com.example.slideoutmenu.LayerStack;
import com.example.slideoutmenu.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class LayerStack extends Activity {
//Declare
private LinearLayout slidingPanel;
private boolean isExpanded;
private DisplayMetrics metrics;
private ListView listView;
private RelativeLayout headerPanel;
private RelativeLayout menuPanel;
private int panelWidth;
private ImageView menuViewButton;
Button menu1, menu2,menu3,menu4 ;
TextView txtpays;
FrameLayout.LayoutParams menuPanelParameters;
FrameLayout.LayoutParams slidingPanelParameters;
LinearLayout.LayoutParams headerPanelParameters ;
LinearLayout.LayoutParams listViewParameters;
ImageView lampada;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layer_stack);
//Initialize
metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
panelWidth = (int) ((metrics.widthPixels)*0.80);
headerPanel = (RelativeLayout) findViewById(R.id.header);
headerPanelParameters = (LinearLayout.LayoutParams) headerPanel.getLayoutParams();
headerPanelParameters.width = metrics.widthPixels;
headerPanel.setLayoutParams(headerPanelParameters);
menuPanel = (RelativeLayout) findViewById(R.id.menuPanel);
menuPanelParameters = (FrameLayout.LayoutParams) menuPanel.getLayoutParams();
menuPanelParameters.width = panelWidth;
menuPanel.setLayoutParams(menuPanelParameters);
slidingPanel = (LinearLayout) findViewById(R.id.slidingPanel);
slidingPanelParameters = (FrameLayout.LayoutParams) slidingPanel.getLayoutParams();
slidingPanelParameters.width = metrics.widthPixels;
slidingPanel.setLayoutParams(slidingPanelParameters);
listView = (ListView) findViewById(R.id.listView1);
listViewParameters = (LinearLayout.LayoutParams) listView.getLayoutParams();
listViewParameters.width = metrics.widthPixels;
listView.setLayoutParams(listViewParameters);
//Slide the Panel ;
//lampada = (ImageView) findViewById(R.id.imagelampada);
menu1 = (Button) findViewById(R.id.menu_item_1);
txtpays = (TextView) findViewById(R.id.listepays);
menu2 = (Button) findViewById(R.id.menu_item_2);
menu3 = (Button) findViewById(R.id.menu_item_3);
menu4 = (Button) findViewById(R.id.menu_item_4);
txtpays.setText("Clique acima para acessar o menu");
clicabotao();
//listaClica();
menuViewButton = (ImageView) findViewById(R.id.menuViewButton);
menuViewButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(!isExpanded){
expandMenu();
}else{
expandList();
}
}
});
}
//############################################# FUNÇÃO CRIA MENUS CLICK ##########################################
// função: executar codigo individual de ação ao clicar em botão do menu aposentos
public void clicabotao(){
// CONFIGURA ONCLICK DOS BOTÕES MENU
menu1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
txtpays.setText("Clique acima para acessar o menu");
expandList();
}catch(Exception e){
Log.i("Mensagem ",""+e.getMessage());
}
}
});
menu2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
txtpays.setText("Clique acima para acessar o menu");
expandList();
}catch(Exception e){
Log.i("Mensagem ",""+e.getMessage());
}
}
});
menu3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
txtpays.setText("Clique acima para acessar o menu");
expandList();
}catch(Exception e){
Log.i("Mensagem ",""+e.getMessage());
}
}
});
menu4.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
txtpays.setText("Clique acima para acessar o menu");
expandList();
}catch(Exception e){
Log.i("Mensagem ",""+e.getMessage());
}
}
});
}
//############################################# FUNÇÃO CRIA ITEM DA LISTVIEW #############################################
//############################################# FUNÇÃO EXPANDE MENU APOSENTOS #############################################
public void expandMenu(){
new ExpandAnimation(slidingPanel, panelWidth,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.75f, 0, 0.0f, 0, 0.0f);
isExpanded = true;
}
//############################################# FUNÇÃO EXPANDE A LISTVIEW ############################################
public void expandList(){
new CollapseAnimation(slidingPanel,panelWidth,
TranslateAnimation.RELATIVE_TO_SELF, 0.80f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f, 0, 0.0f, 0, 0.0f);
isExpanded = false;
}
class ListViewItem{
public int ThumbnailResource;
public String Title;
public String SubTitle;
}
}
ExpandAnimation.java
package com.example.slideoutmenu;
import android.view.Gravity;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.FrameLayout.LayoutParams;
public class ExpandAnimation extends TranslateAnimation implements Animation.AnimationListener{
private LinearLayout slidingLayout;
int panelWidth;
public ExpandAnimation(LinearLayout layout, int width, int fromXType, float fromXValue, int toXType,
float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) {
super(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
//Initialize
slidingLayout = layout;
panelWidth = width;
setDuration(400);
setFillAfter( false );
setInterpolator(new AccelerateDecelerateInterpolator());
setAnimationListener(this);
slidingLayout.startAnimation(this);
}
public void onAnimationEnd(Animation arg0) {
//Create margin and align left
LayoutParams params = (LayoutParams) slidingLayout.getLayoutParams();
params.leftMargin = panelWidth;
params.gravity = Gravity.LEFT;
slidingLayout.clearAnimation();
slidingLayout.setLayoutParams(params);
slidingLayout.requestLayout();
}
public void onAnimationRepeat(Animation arg0) {
}
public void onAnimationStart(Animation arg0) {
}
}
CollapseAnimation.java
package com.example.slideoutmenu;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.FrameLayout.LayoutParams;
public class CollapseAnimation extends TranslateAnimation implements TranslateAnimation.AnimationListener{
private LinearLayout slidingLayout;
int panelWidth;
public CollapseAnimation(LinearLayout layout, int width, int fromXType, float fromXValue, int toXType,
float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) {
super(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
//Initialize
slidingLayout = layout;
panelWidth = width;
setDuration(400);
setFillAfter( false );
setInterpolator(new AccelerateDecelerateInterpolator());
setAnimationListener(this);
//Clear left and right margins
LayoutParams params = (LayoutParams) slidingLayout.getLayoutParams();
params.rightMargin = 0;
params.leftMargin = 0;
slidingLayout.setLayoutParams(params);
slidingLayout.requestLayout();
slidingLayout.startAnimation(this);
}
public void onAnimationEnd(Animation animation) {
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
}
activity_layer_stack.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/blue_bg">
<!-- Menu Panel -->
<RelativeLayout
android:id="#+id/menuPanel"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:gravity="right"
android:background="#drawable/agua_menu"
android:orientation="vertical" >
<Button
android:id="#+id/menu_title_1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="0dp"
android:paddingLeft="15dp"
android:gravity="center_vertical"
android:textColor="#android:color/white"
android:text="#string/menu_title">
</Button>
<Button
android:id="#+id/menu_item_1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:layout_below="#+id/menu_title_1"
android:textColor="#android:color/white"
android:text="Cozinha">
</Button>
<Button
android:id="#+id/menu_item_2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/menu_item_1"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:textColor="#android:color/white"
android:text="Sala">
</Button>
<Button
android:id="#+id/menu_item_3"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/menu_item_2"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:textColor="#android:color/white"
android:text="Suite">
</Button>
<!-- <View
android:id="#+id/menu_item_divider_4"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/menu_item_3"
android:background="#353535"/> -->
<Button
android:id="#+id/menu_item_4"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/menu_item_3"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:textColor="#android:color/white"
android:text="Quarto Hospedes">
</Button>
</RelativeLayout>
<!-- Sliding Panel -->
<LinearLayout
android:id="#+id/slidingPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="left"
android:orientation="vertical"
android:background="#drawable/fundo_branco" >
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="50dp">
<ImageView
android:id="#+id/menuViewButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:clickable="true"
android:contentDescription="#string/description"
android:src="#drawable/icon_menu1"
android:visibility="visible" />
</RelativeLayout>
<TextView
android:id="#+id/listepays"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/menu_item_divider_2"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#00BFFF"
android:textColorHighlight="#550022" >
</TextView>
<View
android:id="#+id/listaDivide"
android:layout_width="fill_parent"
android:layout_height="0.1dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_below="#+id/menuViewButton"
android:background="#000000"/>
<View
android:id="#+id/listaDivide2"
android:layout_width="fill_parent"
android:layout_height="0.1dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_below="#+id/listepays"
android:background="#000000"/>
</LinearLayout>
</FrameLayout>

change slide menu from left-to-right To right-to-left using Animation

in my code ,my slide out menu changes its direction from left to right while i want it to change from right to left, This is my main Activity:
public class LayerStack extends Activity {
// Declare
private LinearLayout slidingPanel;
private boolean isExpanded;
private DisplayMetrics metrics;
private RelativeLayout headerPanel;
private RelativeLayout menuPanel;
private int panelWidth;
private ImageView menuViewButton;
Button menu1;
Button menu2;
TextView txtpays;
FrameLayout.LayoutParams menuPanelParameters;
FrameLayout.LayoutParams slidingPanelParameters;
LinearLayout.LayoutParams headerPanelParameters;
LinearLayout.LayoutParams listViewParameters;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layer_stack);
// Initialize
metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
panelWidth = (int) ((metrics.widthPixels) * 0.75);
headerPanel = (RelativeLayout) findViewById(R.id.header);
headerPanelParameters = (LinearLayout.LayoutParams) headerPanel
.getLayoutParams();
headerPanelParameters.width = metrics.widthPixels;
headerPanel.setLayoutParams(headerPanelParameters);
menuPanel = (RelativeLayout) findViewById(R.id.menuPanel);
menuPanelParameters = (FrameLayout.LayoutParams) menuPanel
.getLayoutParams();
menuPanelParameters.width = panelWidth;
menuPanel.setLayoutParams(menuPanelParameters);
slidingPanel = (LinearLayout) findViewById(R.id.slidingPanel);
slidingPanelParameters = (FrameLayout.LayoutParams) slidingPanel
.getLayoutParams();
slidingPanelParameters.width = metrics.widthPixels;
slidingPanel.setLayoutParams(slidingPanelParameters);
// Slide the Panel
menu1 = (Button) findViewById(R.id.menu_item_1);
menu2 = (Button) findViewById(R.id.menu_item_2);
menuViewButton = (ImageView) findViewById(R.id.menuViewButton);
menuViewButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (!isExpanded) {
isExpanded = true;
// Expand
new ExpandAnimation(slidingPanel, panelWidth,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.75f, 0, 0.0f, 0, 0.0f);
} else {
isExpanded = false;
// Collapse
new CollapseAnimation(slidingPanel, panelWidth,
TranslateAnimation.RELATIVE_TO_SELF, 0.75f,
TranslateAnimation.RELATIVE_TO_SELF, 0.0f, 0, 0.0f,
0, 0.0f);
}
}
});
}
}
This is my expandAnimation class:
public class ExpandAnimation extends TranslateAnimation implements Animation.AnimationListener{
private LinearLayout slidingLayout;
int panelWidth;
public ExpandAnimation(LinearLayout layout, int width, int fromXType, float fromXValue, int toXType,
float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) {
super(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
//Initialize
slidingLayout = layout;
panelWidth = width;
setDuration(400);
setFillAfter( false );
setInterpolator(new AccelerateDecelerateInterpolator());
setAnimationListener(this);
slidingLayout.startAnimation(this);
}
public void onAnimationEnd(Animation arg0) {
//Create margin and align left *******************************put setting in blue lines in left side
LayoutParams params = (LayoutParams) slidingLayout.getLayoutParams();
params.leftMargin = panelWidth;
params.gravity = Gravity.LEFT;
slidingLayout.clearAnimation();
slidingLayout.setLayoutParams(params);
slidingLayout.requestLayout();
}
My Collapse class:
public class CollapseAnimation extends TranslateAnimation implements TranslateAnimation.AnimationListener{
private LinearLayout slidingLayout;
int panelWidth;
public CollapseAnimation(LinearLayout layout, int width, int fromXType, float fromXValue, int toXType,
float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) {
super(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
//Initialize
slidingLayout = layout;
panelWidth = width;
setDuration(400);
setFillAfter( false );
setInterpolator(new AccelerateDecelerateInterpolator());
setAnimationListener(this);
//Clear left and right margins
LayoutParams params = (LayoutParams) slidingLayout.getLayoutParams();
params.rightMargin = 0;
params.leftMargin = 0;
slidingLayout.setLayoutParams(params);
slidingLayout.requestLayout();
slidingLayout.startAnimation(this);
}
and my XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/blue_bg">
<!-- Menu Panel -->
<RelativeLayout
android:id="#+id/menuPanel"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:gravity="right"
android:background="#drawable/gray_bg"
android:orientation="vertical" >
<Button
android:id="#+id/menu_title_1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="0dp"
android:paddingLeft="15dp"
android:gravity="center_vertical"
android:background="#353535"
android:textColor="#android:color/white"
android:text="#string/menu_title">
</Button>
<View
android:id="#+id/menu_item_divider_1"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_below="#+id/menu_title_1"
android:background="#b5b5b5"/>
<Button
android:id="#+id/menu_item_1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:layout_below="#+id/menu_item_divider_1"
android:text="Pays libres ">
</Button>
<View
android:id="#+id/menu_item_divider_2"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/menu_item_1"
android:background="#b5b5b5"/>
<Button
android:id="#+id/menu_item_2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/menu_item_divider_2"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:text="Pays en attente">
</Button>
</RelativeLayout>
<!-- Sliding Panel -->
<LinearLayout
android:id="#+id/slidingPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="left"
android:orientation="vertical"
android:background="#android:color/white" >
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/blue_bg" >
<View
android:id="#+id/header_vertical_divider_1"
android:layout_width="2dp"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/menuViewButton"
android:background="#drawable/engraved_bg" />
<ImageView
android:id="#+id/menuViewButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:clickable="true"
android:contentDescription="#string/description"
android:src="#drawable/icon_menu"
android:visibility="visible" />
</RelativeLayout>
<!-- from this point -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e5e5e5"
android:orientation="vertical" >
</LinearLayout>
<!--
<TextView
android:id="#+id/listepays"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/menu_item_divider_2"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:textColorHighlight="#550022"
android:editable = "true">
</TextView>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="319dp" >
</ListView>
-->
</LinearLayout>
</FrameLayout>
thanks in advance for your help :)

Sliding Menu - From Right to left

I was trying with Sliding menu from the below example.
https://github.com/eddieringle/android-undergarment
But this has the sliding implementation from left to right. How can i change this to Right to left. Can any one please help me to figure this out?
i know you get your answer but if you don't want to use any external library you can use this:
this code exist on gitHub
but this project use for left right menu, with a little change you can open from right to left, i copy code with changes. with following code you can have both side menu.
CollapseAnimation.java
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout.LayoutParams;
import android.widget.LinearLayout;
public class CollapseAnimation extends TranslateAnimation implements TranslateAnimation.AnimationListener{
private LinearLayout slidingLayout;
int panelWidth;
public CollapseAnimation(LinearLayout layout, int width, int fromXType, float fromXValue, int toXType,
float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) {
super(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
//Initialize
slidingLayout = layout;
panelWidth = width;
setDuration(400);
setFillAfter( false );
setInterpolator(new AccelerateDecelerateInterpolator());
setAnimationListener(this);
//Clear left and right margins
LayoutParams params = (LayoutParams) slidingLayout.getLayoutParams();
params.rightMargin = 0;
params.leftMargin = 0;
slidingLayout.setLayoutParams(params);
slidingLayout.requestLayout();
slidingLayout.startAnimation(this);
}
public void onAnimationEnd(Animation animation) {
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
}
ExpandAnimation.java
import android.view.Gravity;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout.LayoutParams;
import android.widget.LinearLayout;
public class ExpandAnimation extends TranslateAnimation implements Animation.AnimationListener{
private LinearLayout slidingLayout;
int panelWidth;
public ExpandAnimation(LinearLayout layout, int width, int fromXType, float fromXValue, int toXType,
float toXValue, int fromYType, float fromYValue, int toYType, float toYValue) {
super(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue);
//Initialize
slidingLayout = layout;
panelWidth = width;
setDuration(400);
setFillAfter( false );
setInterpolator(new AccelerateDecelerateInterpolator());
setAnimationListener(this);
slidingLayout.startAnimation(this);
}
public void onAnimationEnd(Animation arg0) {
//Create margin and align left
LayoutParams params = (LayoutParams) slidingLayout.getLayoutParams();
params.rightMargin = panelWidth;
params.gravity = Gravity.RIGHT;
slidingLayout.clearAnimation();
slidingLayout.setLayoutParams(params);
slidingLayout.requestLayout();
}
public void onAnimationRepeat(Animation arg0) {
}
public void onAnimationStart(Animation arg0) {
}
}
LayerStack.java
import android.os.Bundle;
import android.app.Activity;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ListView;
public class LayerStack extends Activity {
//Declare
private LinearLayout slidingPanel;
private boolean isExpanded;
private DisplayMetrics metrics;
private ListView listView;
private RelativeLayout headerPanel;
private RelativeLayout menuPanel;
private int panelWidth;
private ImageView menuViewButton;
FrameLayout.LayoutParams menuPanelParameters;
FrameLayout.LayoutParams slidingPanelParameters;
LinearLayout.LayoutParams headerPanelParameters ;
LinearLayout.LayoutParams listViewParameters;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_layer_stack);
//Initialize
metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
panelWidth = (int) ((metrics.widthPixels)*0.33);
headerPanel = (RelativeLayout) findViewById(R.id.header);
headerPanelParameters = (LinearLayout.LayoutParams) headerPanel.getLayoutParams();
headerPanelParameters.width = metrics.widthPixels;
headerPanel.setLayoutParams(headerPanelParameters);
menuPanel = (RelativeLayout) findViewById(R.id.menuPanel);
menuPanelParameters = (FrameLayout.LayoutParams) menuPanel.getLayoutParams();
menuPanelParameters.gravity = Gravity.RIGHT;
menuPanelParameters.width = panelWidth;
menuPanel.setLayoutParams(menuPanelParameters);
slidingPanel = (LinearLayout) findViewById(R.id.slidingPanel);
slidingPanelParameters = (FrameLayout.LayoutParams) slidingPanel.getLayoutParams();
slidingPanelParameters.width = metrics.widthPixels;
slidingPanelParameters.gravity = Gravity.LEFT;
slidingPanel.setLayoutParams(slidingPanelParameters);
listView = (ListView) findViewById(R.id.list);
listViewParameters = (LinearLayout.LayoutParams) listView.getLayoutParams();
listViewParameters.width = metrics.widthPixels;
listView.setLayoutParams(listViewParameters);
//Slide the Panel
menuViewButton = (ImageView) findViewById(R.id.menuViewButton);
menuViewButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if(!isExpanded){
isExpanded = true;
//Expand
new ExpandAnimation(slidingPanel, panelWidth,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -0.33f, 0, 0.0f, 0, 0.0f);
// if you want left to right just remove ( - ) before 0.33f
}else{
isExpanded = false;
//Collapse
new CollapseAnimation(slidingPanel,panelWidth,
TranslateAnimation.RELATIVE_TO_PARENT,-0.33f,
TranslateAnimation.RELATIVE_TO_PARENT, 0.0f, 0, 0.0f, 0, 0.0f);
// if you want left to right just remove ( - ) before 0.33f
}
}
});
}
}
activity_layer_stack.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/blue_bg">
<!-- Menu Panel -->
<RelativeLayout
android:id="#+id/menuPanel"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:gravity="right"
android:background="#drawable/gray_bg"
android:orientation="vertical" >
<TextView
android:id="#+id/menu_title_1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="0dp"
android:paddingLeft="15dp"
android:gravity="center_vertical"
android:background="#353535"
android:textColor="#android:color/white"
android:text="#string/menu_title">
</TextView>
<View
android:id="#+id/menu_item_divider_1"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_below="#+id/menu_title_1"
android:background="#b5b5b5"/>
<TextView
android:id="#+id/menu_item_1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:layout_below="#+id/menu_item_divider_1"
android:text="#string/item_1">
</TextView>
<View
android:id="#+id/menu_item_divider_2"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/menu_item_1"
android:background="#b5b5b5"/>
<TextView
android:id="#+id/menu_item_2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_below="#+id/menu_item_divider_2"
android:layout_marginLeft="15dp"
android:gravity="center_vertical"
android:text="#string/item_2">
</TextView>
<View
android:id="#+id/menu_item_divider_3"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/menu_item_2"
android:background="#b5b5b5" />
</RelativeLayout>
<!-- Sliding Panel -->
<LinearLayout
android:id="#+id/slidingPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right"
android:orientation="vertical"
android:background="#android:color/white" >
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/blue_bg" >
<View
android:id="#+id/header_vertical_divider_1"
android:layout_width="2dp"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/menuViewButton"
android:background="#drawable/engraved_bg" />
<ImageView
android:id="#+id/menuViewButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:contentDescription="#string/description"
android:src="#drawable/icon_menu"
android:visibility="visible" />
</RelativeLayout>
<View
android:id="#+id/dividerHeaderBottom"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#414141" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:divider="#b5b5b5"
android:dividerHeight="0.5dp"
android:background="#android:color/white"
>
</ListView>
</LinearLayout>
</FrameLayout>
https://github.com/jfeinstein10/SlidingMenu
Try this. It has different modes like from right to left and many other customizations

Categories

Resources