thomas thomas - 6 months ago 21
Java Question

How to add relative layout to relative layout with slide in effect?

I have a relative layout in which i add a second relative layout which contains 4 buttons. when i do:


relativeLayout1.addView(relativeLayout2,params)

i want that the added relative layout with the 4 buttons slides in from right to left.

example

Is that somehow possible?

xml:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="100%"
android:toXDelta="0%" >
</translate>


code:
```

public Panel(Context context) {
super(context);

this.setBackgroundColor(Color.BLACK);
this.setId(R.id.panel);

right_menubar = new RelativeLayout(context);
right_menubar.setId(R.id.panel_indicators);

plp_right_menu_bar = new RelativeLayout.LayoutParams(100, 100);

this.addView(right_menubar, plp_right_menu_bar);

Animation fadeIn = AnimationUtils.loadAnimation(context, R.animator.anim);
right_menubar.startAnimation(fadeIn);

}

Answer

It is working now,

right_menubar.setId(R.id.panel_indicators);
plp_right_menu_bar = new RelativeLayout.LayoutParams(100, 100);
plp_right_menu_bar.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
this.addView(right_menubar, plp_right_menu_bar);
right_menubar.startAnimation(AnimationUtils.loadAnimation(this.getContext(), R.animator.anim));

No need to set it to invisible before the animation.