Reputation: 5234
I am trying my custom sliding navigation. I know there are already lot's of tutorial or library is available but this is for my own purpose.
So basically i am trying to open sliding menu and it is opening left to right
now i want to change it's direction from right to left
. How can i do this.
Below is my code.
public class Profile extends Activity implements OnClickListener {
private int windowWidth;
boolean alreadyShowing = false;
private Animation mAnimation;
LayoutInflater mLayoutInflater;
private RelativeLayout mRelativeLayout;
ImageView sliding_menu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.profile);
Display display = getWindowManager().getDefaultDisplay();
windowWidth = display.getWidth();
display.getHeight();
mLayoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
sliding_menu = (ImageView) findViewById(R.id.slidingMenu);
sliding_menu.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (!alreadyShowing) {
alreadyShowing = true;
openSlidingMenu();
}
}
});
}
private void openSlidingMenu() {
int width = (int) (windowWidth * 0.8f);
translateView((float) (width));
int height = LayoutParams.FILL_PARENT;
final View layout = mLayoutInflater.inflate(R.layout.settings,
(ViewGroup) findViewById(R.id.setting));
final PopupWindow optionsPopup = new PopupWindow(layout, width, height,
true);
optionsPopup.setBackgroundDrawable(new PaintDrawable());
optionsPopup.showAtLocation(layout, Gravity.NO_GRAVITY, 0, 0);
optionsPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
public void onDismiss() {
cleanUp();
translateView(0);
cleanUp();
alreadyShowing = false;
}
});
}
private void translateView(float right) {
mAnimation = new TranslateAnimation(0f, right, 0f, 0f);
mAnimation.setDuration(100);
mAnimation.setFillEnabled(true);
mAnimation.setFillAfter(true);
mRelativeLayout = (RelativeLayout) findViewById(R.id.profile);
mRelativeLayout.startAnimation(mAnimation);
mRelativeLayout.setVisibility(View.VISIBLE);
}
private void cleanUp() {
if (null != mRelativeLayout) {
mRelativeLayout.clearAnimation();
mRelativeLayout = null;
}
if (null != mAnimation) {
mAnimation.cancel();
mAnimation = null;
}
}
So basically you can see in above image that my menu is opening from left to right
, how can i change it from right to left
.
Thank you in advance.
Upvotes: 3
Views: 760
Reputation: 5234
I have solved this question, i have just changed gravity to right side of this below line and it is working now.
optionsPopup.showAtLocation(layout, Gravity.RIGHT, 0, 0);
So before change my code was something like this.
final PopupWindow optionsPopup = new PopupWindow(layout, width, height,true);
optionsPopup.setBackgroundDrawable(new PaintDrawable());
optionsPopup.showAtLocation(layout, Gravity.NO_GRAVITY, 0, 0);
and now it is like below
final PopupWindow optionsPopup = new PopupWindow(layout, width, height,true);
optionsPopup.setBackgroundDrawable(new PaintDrawable());
optionsPopup.showAtLocation(layout, Gravity.RIGHT, 0, 0);
Thank you all for helping me.
Upvotes: 2