---
title: "activity横竖屏翻转不重载"
author: "dss16694"
date: "2011-12-15T00:16:20Z"
tags: []
categories: ["移动开发"]
slug: "activity"
draft: false
lastmod: "2011-12-15T00:15:57Z"
id: 1311045
url: "https://dss16694.iteye.com/blog/1311045"
---

可以给每个activity加上android:configChanges="keyboardHidden|orientation"属性,就不会重启activity.而是去调用onConfigurationChanged(Configuration newConfig). 这样就可以在这个方法里调整显示方式.   
比如   
Java代码   
if(newConfig.orientation==Configuration.ORIENTATION\_LANDSCAPE){     
    //横向     
    setContentView(R.layout.file\_list\_landscape);     
}else{     
    //竖向     
    setContentView(R.layout.file\_list);     
}