私はあなたがほとんどそれを得ると思います。同様のことをしているかどうかはわかりませんが、これは、向きが変わるとすぐに UI の変更を行うことができます。この例では、 からROTATION_270
への変更のみを行いましたが、 からへROTATION_90
のすべてのケースをカバーできるようにコードに追加できます。私の例では、向きが変わったときにテキストビューを "横" から "逆横" に変更するだけです。 PORTRAIT
REVERSE_PORTRAIT
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
コード
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.OrientationEventListener;
import android.view.Surface;
import android.widget.TextView;
public class LandScapeToLandScapeReverse extends Activity
{
private int mCurrentOrientation;
private Display mDisplay;
private OrientationEventListener mOrientationEventListener;
private TextView mTextView;
private static final String TAG = "LandScape To LandScape Reverse";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate");
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById(R.id.textview);
mDisplay = getWindowManager().getDefaultDisplay();
mCurrentOrientation = mDisplay.getRotation();
mTextView.setText("CurrentOrientation: " + mCurrentOrientation);
mOrientationEventListener = new OrientationEventListener(this)
{
@Override
public void onOrientationChanged(int orientation)
{
// On my phone it seem to change at 233 maybe should start lower
// to take into account of phones model variations.
if (mCurrentOrientation == Surface.ROTATION_270 && orientation > 230)
{
mTextView.setText("CurrentOrientation: " + orientation);
Log.d(TAG, "orientation = " + orientation
+ " getRotation: " + mDisplay.getRotation());
if (mDisplay.getRotation() != mCurrentOrientation)
{
// I think one should disable listener here and enable
// again after doing all the UI changes.
mOrientationEventListener.disable();
mTextView.setText("Landscape reverse");
}
}
}
};
mOrientationEventListener.enable();
}
@Override
protected void onDestroy()
{
super.onDestroy();
Log.d(TAG, "onDestroy");
mOrientationEventListener.disable();
}
}
オーバーライドできる方向変更の前に呼び出される関数があるのではないかと思いました。遊んでみて、見つけたら答えを更新します。