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: 
Clearly one would prefer to group the media query versions of the CSS rules together with the non-media query versions, so they can be managed together. For example, if I write separate CSS for each component, I would usually want both media query versions and non-media query versions of the rules for that component to be in the file for that component. When I add and modify rules, I would prefer to do that in one place, rather than two or more.

If it bothers you that you have to write the media query again and again, which is a valid concern from the standpoint of maintaining your code when changing breakpoints, consider using a preprocessor such as postCSS which allows you to define aliases for media queries. For instance, [this plugin](https://github.com/postcss/postcss-custom-media) would allow you to write

```
@custom-media --small-viewport (max-width: 30em);

@media (--small-viewport) {
  /* styles for small viewport */
}

```
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.