【发布时间】:2015-06-02 15:14:45
【问题描述】:
我在不同的文件夹中有 3 个布局:
1.layout/HomeLayout.axml(其中 layout 是布局文件夹,HomeLayout.axml 是全局 axml 文件)。
2.layout-large-port/HomeLayout.amxl(其中layout-large-port是大(显示尺寸)纵向的文件夹,HomeLayout.axml是axml文件)。
3.layout-large-land/HomeLayout.axml(layout-large-land 是大(显示尺寸)景观的文件夹,HomeLayout.axml 是 axml文件)。
在这个活动中,我得到了带有一些数据的 ListView,当我将手机从 portrait 旋转到 landscape > ,我需要保存我在 Portrait 模式下制作的所有内容(listview 上的每一行都有不同的东西,如 buttons/textview 等)并显示横向。
那么现在做了什么。在 HomeActivity 我声明了这一点:
ConfigurationChanges=Android.Content.PM.ConfigChanges.Orientation
这个 sn-p 效果很好,但有一个大问题:旋转后(从 Portrait 到 Landscape)仍然是布局 Portrait。我该如何解决?
我也尝试覆盖方法OnConfigurationChanged:
public override void OnConfigurationChanged(Android.Content.Res.Configuration newConfig)
{
base.OnConfigurationChanged (newConfig);
if(newConfig.Orientation == Android.Content.Res.Orientation.Landscape)
{
SetContentView(Resource.Layout.ProductsLayout); //system understand that now is Landscape and put correct layout;
}
else
{
SetContentView(Resource.Layout.ProductsLayout); //same here
}
所以这个方法对我没有帮助,因为当我旋转手机时,布局设置正确但没有数据(列表视图为空),之后,当我试图从 横向返回时 到 纵向,布局设置正确但列表为空。
有什么建议吗?
PS 对不起我的英语!
【问题讨论】:
标签: android xamarin mono orientation