указать разные макеты для портретной и альбомной ориентации? - PullRequest
4 голосов
/ 22 марта 2012

Я указал два отдельных XML-файла макета для действия, один для Portrait в папке res / layout и один для Landscape в папке res / layout-land.Моя настоящая проблема заключается в том, что когда я запускаю приложение в портретном режиме, он берет пользовательский интерфейс из макета и мгновенно поворачивает телефон, он не берет XML из папки layout-land, он берет пользовательский интерфейс из папки макета, и если я запускаю свое приложение в альбомном режиме, то этоберет xml из папки layout-land и мгновенно поворачивает my в портретный режим, он берет xml из layout-land ui, не меняется на Portrait UI.

Может ли любой собеседник сказать мне, в чём проблема, есть ли какие-либо настройки, необходимые длячто плз помогите мне решить эту проблему.

Заранее спасибо.

    this is my landscape ui xml

        <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/widget57"
        android:layout_width="400dp"
        android:layout_height="400dp"
        android:layout_gravity="center|center_vertical"
        android:layout_marginTop="30dp"
        android:orientation="vertical" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp" >

            <TextView
                android:id="@+id/txtName"
                android:layout_width="90dp"
                android:text="@string/UserName" />

            <EditText
                android:id="@+id/edName"
                android:imeOptions="actionNext|actionDone"
                android:paddingRight="10dp"
                android:singleLine="true"
                android:width="240dp" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/txtPass"
                android:layout_width="90dp"
                android:text="@string/PassWord" />

            <EditText
                android:id="@+id/edPass"
                android:imeOptions="actionGo"
                android:paddingRight="10dp"
                android:password="true"
                android:singleLine="true"
                android:width="240dp" />
        </TableRow>

         <LinearLayout
            android:id="@+id/widget57"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:orientation="vertical" >

            <Button
                android:id="@+id/btnLogin"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:text="@string/btn_GO"
                android:textSize="19sp" >
            </Button>

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="30dp"
                android:text="CoinOp Solutions"
                android:textSize="30sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:text="Version 0.1" />
        </LinearLayout>


    </TableLayout>

    this is my Portrait ui

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

        <TextView
            android:id="@+id/txt_Required"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:text=""
            android:textColor="#ffff0000" >
        </TextView>

        <TextView
            android:id="@+id/txtName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
            android:text="@string/UserName" >
        </TextView>

        <EditText
            android:id="@+id/edName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:imeOptions="actionNext|actionDone"
            android:singleLine="true"
            android:textSize="18sp" >
        </EditText>

        <TextView
            android:id="@+id/txtPass"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:text="@string/PassWord" >
        </TextView>

        <EditText
            android:id="@+id/edPass"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:imeOptions="actionGo"
            android:maxLines="1"
            android:password="true"
            android:singleLine="true"
            android:textSize="18sp" >
        </EditText>

        <LinearLayout
            android:id="@+id/widget57"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:orientation="vertical" >

            <Button
                android:id="@+id/btnLogin"
                android:layout_width="150dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:text="@string/btn_GO"
                android:textSize="19sp" >
            </Button>

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="30dp"
                android:text="CoinOp Solutions"
                android:textSize="30sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="10dp"
                android:text="Version 0.1" />
        </LinearLayout>

    </LinearLayout>

Мой файл манифеста

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

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <application
        android:debuggable="true"
        android:icon="@drawable/coinop"
        android:label="@string/app_name"
        android:theme="@style/CustomTheme" >
        <activity
            android:name=".LoginActivity"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:windowSoftInputMode="stateVisible|adjustPan" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ShowDbList"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustPan" >
        </activity>
        <activity
            android:name=".Menu"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustPan" >
        </activity>

Ответы [ 3 ]

7 голосов
/ 22 марта 2012

У вас есть android:configChanges="orientation" в вашем манифесте. Согласно документ configChanges содержит список действий, которые вы будете выполнять самостоятельно.

При удалении android:configChanges="orientation" раскладка будет изменяться при повороте телефона. В противном случае вы должны справиться с этим самостоятельно.

2 голосов
/ 22 марта 2012

Не уверен, поможет ли это, но вы можете попробовать (если вы этого еще не сделали):

  1. в действии, в котором используется макет, переопределите onConfigurationChanged и снова установитеConConViewView.
  2. remove android: configChanges = "direction" для действия, использующего макет
1 голос
/ 22 марта 2012

Вы должны попытаться добавить:

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
    Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
    Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}

} И установить макет вручную через setContentView (..) в Activity. Надеюсь, это поможет. Проверьте больше на: http://developer.android.com/guide/topics/resources/runtime-changes.html

...