纵向和横向应用时出错

  • 本文关键字:出错 应用 横向 android
  • 更新时间 :
  • 英文 :


我在尝试旋转设备以纵向模式测试我的应用程序时,我的应用程序出错。我的应用程序由4个编辑文本和4个文本视图组成,该应用程序支持2种语言,阿拉伯语和英语,因此当我的手机是英语时,该应用程序在纵向模式下运行良好。 但是当我尝试更改阿拉伯语语言并且将设备置于纵向模式时,该应用程序以横向模式显示。 我已经编写了用于显示横向模式的命令。但是为什么当我将语言更改为阿拉伯语时,应用程序显示为横向模式>???

清单.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>

布局.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

尝试在 Android 清单中的活动代码中添加以下内容.xml :

android:configChanges="locale"

但是使用它要仔细经历这个,它的快速和肮脏的修复。否则,您应该通过在活动中重写onConfigurationChanged方法来处理它

相关内容

最新更新