纵向和横向的Android布局问题

时间:2015-12-15 06:44:16

标签: android android-layout landscape-portrait

朋友们,您好我是Android开发和Stackoverflow的新手, 我在Android布局中面临一些问题, 我创建了两个布局文件夹,一个用于纵向,一个用于横向(均用于平板电视TVDPI)

layout-sw600dp-land-tvdpi &的布局sw600dp端口-tvdpi

我面临的问题是,当我以纵向模式运行程序时,它会向我显示正确的纵向布局,但当我将设备纵向转为横向时,它会显示相同的纵向布局,同样的情况下我运行它在横向模式下正确运行并转向potrait它向我展示了景观布局......

为什么?

1 个答案:

答案 0 :(得分:0)

试试这个

 #region Handle State on Orientation
    //this has been done using better technique
    protected override void OnSaveInstanceState(Bundle outState)
    {
        base.OnSaveInstanceState(outState);
        //adding spinner/dropdownlist selected item
        if (ViewModel.IsLoading == true)
        {
            isLoadingState = true;
            AndroidHUD.AndHUD.Shared.Dismiss(this);
        }
        var preferences = GetSharedPreferences("TmsAppData", FileCreationMode.Private);
        var editor = preferences.Edit();
        //editor.PutString("DeviceId", registrationId);
        editor.PutBoolean("IsOrientationChange", true);
        editor.Commit();
        //outState.PutInt("_AlreadySelectedPostion", _AlreadySelectedPostion);
        outState.PutBoolean("_isLoadingState", isLoadingState);
    }
    protected override void OnRestoreInstanceState(Bundle savedInstanceState)
    {
        base.OnRestoreInstanceState(savedInstanceState);
        //setting a flag to manage spinner selected state
        _IsStateViewActive = true;
        isLoadingState = savedInstanceState.GetBoolean("_isLoadingState");
        if (ViewModel.IsLoading == true)
        {
            isLoadingState = false;
            ViewModel.IsLoading = true;
        }

        //getting the previous selected item from the saved state for spinner / dropdownlist
        //_AlreadySelectedPostion = savedInstanceState.GetInt("_AlreadySelectedPostion");
    }

    #endregion