Question: 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](https://i.stack.imgur.com/qNHDk.png)](https://i.stack.imgur.com/qNHDk.png)

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 really depends on you. There is no "right" way to do it. It depends on how you wish to organize your stylesheets. If you have many media query rules for different viewports, then it might make more sense to do it the way you've been doing, because you're right -- it is more efficient to have sections for different media queries. The examples that you've looked at may be doing it differently to make it more easily understood to other people reading it. I think the only important thing is to try to choose a way and stick to it as much as you reasonably can. (At the same time, rules are meant to be broken occasionally.) In the long run, this will help your code be more predictable, and it'll be easier for you to understand and maintain it.
For the examples given it mostly boils down to a personal preference, there are pros and cons for both examples.

The first example, having a single `@media` rule adheres to the [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) principles, which are considered best practise. The downside to this is that it may not be clear right away that some different styling may apply to those elements.

The second example, having `@media` rules following the initial declaration appear to make the declarations easier to follow as one immediately can see things will be different for different `@media`. Though it is not DRY.

---

I prefer the first approach, adding the `@media` rules to the stylesheet as late as possible and having multiple overrides in them.

My reasons for doing so are simple:

* it's DRY by design
* if you ever feel to need to have the media queries on `<link>`-elements you can more easily extract those into separate files
* it never stops with just one `@media` rule, there will be more and when that happens, all readability/clarity arguments in favor of the second approach (immediate overrides) lose their value as you'll get clutter.