横向到纵向视图不起作用

时间:2013-02-12 12:19:51

标签: android android-orientation

我想根据方向更改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>

1 个答案:

答案 0 :(得分:3)

将文件夹名称layout-port重命名为layout,并在manifest.xml文件中添加activity标记

中的属性
<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>