2013-02-12 60 views
0

我想根據方向更改我的view。 爲此,我創建了資源中的文件夾layout-land & layout-port。 視圖風景的方向肖像正在工作,但風景到肖像視圖不起作用。爲什麼發生這種情況?風景到縱向視圖不起作用

我.manifest的文件代碼:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="in.wptrafficanalyzer.landportdemo" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk android:minSdkVersion="10" /> 

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    </application> 
    </manifest> 

端口/ main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="this is my portrait view" 
    android:layout_gravity="center_horizontal" 

    /> 

</LinearLayout> 

土地/ main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="this is my Landscape view" 
    android:layout_gravity="center_horizontal" 

    /> 

    </LinearLayout> 
+0

在問題 – Pratik 2013-02-12 12:21:20

+0

中發佈您的androidmanifest.xml代碼以及佈局和視圖的相關代碼。 – andr 2013-02-12 12:22:40

+0

你有沒有創建佈局XML文件到這些文件夾..? – 2013-02-12 12:34:34

回答

3

重命名文件夾名稱佈局端口布局僅在manifest.xml文件中添加活動標記中的屬性

<activity 
    android:name=".MainActivity" 
    android:label="@string/app_name" 
    android:configChanges="orientation|screenSize"> 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 

     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity>