断言加载哪个布局?

时间:2015-03-31 10:32:13

标签: android testing

我正在设置两种不同的布局,一种用于横向模式,另一种用于纵向模式。 现在我想断言哪一个被设置 public void testOrienationChange(){

getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            getInstrumentation().waitForIdleSync();
            assert which one is visible/set
    getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
assert which one is visible/set

如何测试从测试类设置或可见的布局?

1 个答案:

答案 0 :(得分:0)

试试这个:

 @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);

            // Checks the orientation of the screen
            if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
                Log.e("Orientation obsetvationActivity", "landscape");
                Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
            } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
                Log.e("Orientation obsetvationActivity", "portrait");
                Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
            }
        }

在活动(<Activity ...>)标签下的清单中添加此

android:configChanges="screenSize"