Question: I need to be able to rotate whole layouts on the fly (on the click of a button).

I am able to rotate the layouts using, eg. `layout.setRotation(270.0f)`. **The problem is, after the rotation, the layout `height` and `width` are not matching its parent's**.

I have tried inverting `height` and `width` like so, 

```
RelativeLayout layout = (RelativeLayout)findViewById(R.id.rootLayout);
LayoutParams layoutParams = layout.getLayoutParams();
int height = layout.getHeight();
int width = layout.getWidth();
layoutParams.height = width;
layoutParams.width = height;

```

Which does nothing at all.

I am working with `sdk 14`.

The first image below is the app as it starts. The second one, after a rotation. I wish to fill the black "space". Any help would be appreciated.

The images below show only a button in the layout. However, in reality, the layout are a lot more complex. What I am trying to achieve is "faking" a landscape view.

![When starting](https://i.stack.imgur.com/z3x4r.png)
![After rotation](https://i.stack.imgur.com/iU5D2.png)

**Edit:** Changed images and added descriptions.

Answer: 
If you want to literally rotate the screen, you can [force a screen orientation](https://stackoverflow.com/questions/14587085/how-can-i-globally-force-screen-orientation-in-android).
Otherwise there's no easy way to do what you are trying to do as `View.setRotation(float)` will always render the `View` in its "real" bounds and **then** rotate it! What I suggest is careful consideration of what elements of the layout should be rotated and then to rotate those specifically.

The only true "automatic" way of achieving it would be to create a custom layout that essentially measures, layouts and draws children rotated... Honestly I would only go there if I really, **really** needed to and it's probably more trouble than it's worth!
i'll suggest you rotate only button rather than rotating the whole layout like 

```
btn_rotate.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) 
{
    rotation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.rotate);
    rotation.setFillAfter(true);
    btn_rotate.startAnimation(rotation);
}
});

```

rotate.xml
----------

```
<set>
    <rotate
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:duration="0"
          android:fromDegrees="270"
          android:pivotX="50%"
          android:pivotY="50%"
          android:startOffset="0"
          android:toDegrees="270" />
</set>

```