0

デバイスの回転後にコンテンツ ビューの高さを見つけようとしています。以下のコードは、起動時と回転後に ContentView.bottom を出力します。デバイスを縦向きモードで起動し、横向きモードに回転し、縦向きモードに戻すと、989,989,565 と出力されます。最初の 989 は正しいですが、他の 2 つの数字は間違っています。これらは回転前の ContnetView のサイズです。

ContentVew のサイズを印刷する前に、回転によるレイアウトの変更が終了したことを検出する方法はありますか?

アクティビティは次のフラグを設定します。

android:configChanges="keyboardHidden|orientation"  

public class TempProjActivity extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        printContentBottom();

    }

    @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        //this occurs when device is rotated or keyboard is exposed/hidden
        super.onConfigurationChanged(newConfig);
        printContentBottom();
    }

    private void printContentBottom()
    {
        getWindow().findViewById(Window.ID_ANDROID_CONTENT).post(new Runnable() {

            @Override
            public void run() {

                Log.e("", getWindow().findViewById(Window.ID_ANDROID_CONTENT).getBottom()+"");
            }
        });
    }
}
4

0 に答える 0