【发布时间】:2017-04-06 14:28:59
【问题描述】:
我有一个非常奇怪的问题:我有一个带有 EditText 的活动、三个按钮和两个用于处理方向更改的布局文件。当我以纵向启动应用程序并旋转设备时,android 会保留纵向布局,但如果我以横向启动应用程序,android 会加载适当的横向布局文件,但即使在旋转到纵向布局后也会再次保留横向布局。这只发生在包含 EditText 的活动中。怎么了?这是我的代码: 1)Manifest.xml:
<activity
android:name=".AnalyzeTextActivity"
android:configChanges="orientation|screenSize|screenLayout"
android:parentActivityName=".StartScreenActivity"
android:windowSoftInputMode="adjustPan"
/>
2) 肖像
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_analyze_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ADD5F7"
android:clickable="true"
android:focusableInTouchMode="true"
>
<EditText
android:layout_width="match_parent"
android:layout_height="200dp"
android:gravity="start"
android:id="@+id/edit_text_analysis"
android:hint="@string/edit_text_hint"
android:isScrollContainer="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="@+id/button_upload_file"
android:background="@drawable/button_upload_large"
android:onClick="onUploadClicked"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/button_upload_file"
android:layout_marginTop="10dp"
android:id="@+id/button_start_analysis"
android:background="@drawable/button_start_large"
android:onClick="onStartClicked"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@+id/button_start_analysis"
android:layout_marginTop="50dp"
android:background="@drawable/button_clear_large"
android:onClick="onClearClicked"/>
</RelativeLayout>
3) 风景
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_analyze_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ADD5F7"
android:clickable="true"
android:focusableInTouchMode="true"
>
<EditText
android:layout_width="match_parent"
android:layout_height="200dp"
android:gravity="start"
android:id="@+id/edit_text_analysis"
android:hint="@string/edit_text_hint"
android:isScrollContainer="true"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/edit_text_analysis"
android:layout_toLeftOf="@+id/button_start_analysis"
android:layout_marginRight="5dp"
android:id="@+id/button_upload_file"
android:layout_marginTop="2dp"
android:background="@drawable/button_upload_small"
android:onClick="onUploadClicked"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edit_text_analysis"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:id="@+id/button_start_analysis"
android:background="@drawable/button_start_small"
android:onClick="onStartClicked"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edit_text_analysis"
android:layout_toRightOf="@+id/button_start_analysis"
android:layout_marginLeft="5dp"
android:layout_marginTop="2dp"
android:background="@drawable/button_clear_small"
android:onClick="onClearClicked"/>
</RelativeLayout>
【问题讨论】:
-
你能分享你的布局文件吗?
-
@Volodymyr Khodonovych 完成
-
检查请在下面回答
-
您能否分享一下您放置纵向和横向布局的文件夹名称
-
@Sumit Pathak 布局和布局土地
标签: android xml android-layout