应用程序纵向和横向时出错

时间:2018-05-24 16:58:39

标签: android

尝试旋转设备时,我的应用程序出错了在纵向模式下测试我的应用程序。我的应用程序包括4个editTexts和4个textviews,该应用程序支持2种语言,阿拉伯语和英语,所以当我的手机是英语时,应用程序在纵向模式下工作正常。 但是,当我尝试更改阿拉伯语中的语言时,当我将设备置于纵向模式时,应用程序将以横向模式显示。 我已经编写了用于显示横向模式的命令。但是,当我将语言更改为阿拉伯语时,为什么应用程序显示为横向模式> ???

的Manifest.xml

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:screenOrientation="portrait"
    android:launchMode = "singleInstance"

    android:theme="@style/AppTheme">
    <activity android:name=".personal_info.Personal_Info_Activity"
        android:screenOrientation="portrait"
        >

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





</application>

Layout.xml

    <?xml version="1.0" encoding="utf-8"?>
<TableLayout
    android:stretchColumns="1"
    android:padding="@dimen/padding_Personal_Info"
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"

    android:layout_height="match_parent">


    <TextView
        android:id = "@+id/Military_Num_TextView"
        android:textSize="@dimen/Title_Size"
        android:text="@string/personal_data"
        android:layout_width="wrap_content"
        android:textColor="@color/Black"
        android:layout_height="wrap_content" />



    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/Table_row_Margin_Top">
        <TextView
            android:id = "@+id/Military_Num"
            android:text="@string/military_number"
            android:layout_width="wrap_content"
            android:gravity="right"
            android:layout_marginRight="@dimen/TxtView_margin_right"
            android:textSize="@dimen/Personal_Information_Text_Size"
            android:textColor="@color/Black"
            android:layout_height="wrap_content"
            />

        <EditText

            android:inputType="number"
            android:layout_marginRight="@dimen/TxtView_margin_right"
            android:background="@drawable/editbox_background"
            android:layout_width="match_parent"
            android:layout_height="@dimen/EditText_Height"
            />
    </TableRow>




    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/Table_row_Margin_Top">
        <TextView
            android:id = "@+id/Name"
            android:text="@string/Name"
            android:gravity="right"
            android:layout_marginRight="@dimen/TxtView_margin_right"
            android:layout_width="wrap_content"
            android:textSize="@dimen/Personal_Information_Text_Size"
            android:textColor="@color/Black"
            android:layout_height="wrap_content" />

        <EditText

            android:inputType="text"
            android:layout_marginRight="@dimen/TxtView_margin_right"
            android:background="@drawable/editbox_background"
            android:layout_width="match_parent"
            android:layout_height="@dimen/EditText_Height"
            />
    </TableRow>









    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/Table_row_Margin_Top">
        <TextView
            android:id = "@+id/Rank"
            android:text="@string/Rank"
            android:gravity="right"
            android:layout_marginRight="@dimen/TxtView_margin_right"
            android:layout_width="wrap_content"
            android:textSize="@dimen/Personal_Information_Text_Size"
            android:textColor="@color/Black"
            android:layout_height="wrap_content" />

        <EditText

            android:inputType="text"
            android:layout_marginRight="@dimen/TxtView_margin_right"
            android:background="@drawable/editbox_background"
            android:layout_width="match_parent"
            android:layout_height="@dimen/EditText_Height"
            />
    </TableRow>








    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/Table_row_Margin_Top">
        <TextView
            android:id = "@+id/Date_of_Birth"
            android:text="@string/Date_of_Birth"
            android:gravity="right"
            android:layout_marginRight="@dimen/TxtView_margin_right"
            android:layout_width="wrap_content"
            android:textSize="@dimen/Personal_Information_Text_Size"
            android:textColor="@color/Black"
            android:layout_height="wrap_content" />

        <EditText
            android:inputType="date"
            android:layout_marginRight="@dimen/TxtView_margin_right"
            android:background="@drawable/editbox_background"
            android:layout_width="match_parent"
            android:layout_height="@dimen/EditText_Height"
            />
    </TableRow>







    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/Table_row_Margin_Top">
        <TextView
            android:id = "@+id/Phone_Number"
            android:text="@string/Phone_Number"
            android:gravity="right"
            android:layout_marginRight="@dimen/TxtView_margin_right"
            android:layout_width="wrap_content"
            android:textSize="@dimen/Personal_Information_Text_Size"
            android:textColor="@color/Black"
            android:layout_height="wrap_content" />

        <EditText

            android:inputType="phone"
            android:layout_marginRight="@dimen/TxtView_margin_right"
            android:background="@drawable/editbox_background"
            android:layout_width="match_parent"
            android:layout_height="@dimen/EditText_Height"
            />
    </TableRow>







    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/Table_row_Margin_Top">
        <TextView
            android:id = "@+id/E-mail"
            android:text="@string/E_mail"
            android:gravity="right"
            android:layout_marginRight="@dimen/TxtView_margin_right"
            android:layout_width="wrap_content"
            android:textSize="@dimen/Personal_Information_Text_Size"
            android:textColor="@color/Black"
            android:layout_height="wrap_content" />

        <EditText

            android:inputType="number"
            android:layout_marginRight="@dimen/TxtView_margin_right"
            android:background="@drawable/editbox_background"
            android:layout_width="match_parent"
            android:layout_height="@dimen/EditText_Height"
            />
    </TableRow>

的java

    package com.example.computer.completionofthestudy.personal_info;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.example.computer.completionofthestudy.R;

public class Personal_Info_Activity extends AppCompatActivity {


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.personal_info);

}

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.lang_ch:
                Toast.makeText(getApplicationContext(),
                        "SignatureView is empty: ", Toast.LENGTH_SHORT).show();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }






}









</TableLayout>

错误的2张照片: -

英语:https://ibb.co/buvud8 阿拉伯语:https://ibb.co/eWtQko

1 个答案:

答案 0 :(得分:0)

尝试将以下内容添加到AndroidManifest.xml中的Activity标记:

android:configChanges="locale"

但请仔细使用它this,快速而肮脏的修复。否则,您应该通过覆盖活动中的 onConfigurationChanged 方法来处理它