安卓:停止重新创建活动的方向变化 [英] Android: Stop Recreating the activity on orientation change

查看:106
本文介绍了安卓:停止重新创建活动的方向变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的main.xml中布局两个按钮的列表视图。上点击一个按钮的我'动态创建一个TextView并将它添加在屏幕的底部,以确认用户的互动。当用户点击第二个按钮(确认按钮),我需要的文本添加到列表视图。为了支持横向模式,我在布局土地文件夹相同的布局文件。当我点击第一个按钮,它创造了一些文字一个TextView,并在屏幕下方增加。现在,如果改变设备的方向,然后它加载的是景观的main.xml和活动再次重现。所以,我的TextView是越来越倒塌。我怎样才能prevent该活动对方向变化的娱乐。 (但它应该拿起另一个布局文件)。

I have a listview with two buttons in my main.xml layout. On click of one button i'am creating a textview dynamically and adding it at the bottom of the screen to confirm the user interaction. When the user clicks 2nd button (Confirm button), i need to add that text to listview. To support landscape mode, i have the same layout file in layout-land folder. When i click on 1st button it is creating a textview with some text and adding at bottom of the screen. Now if a change the device orientation then it is loading the landscape main.xml and activity is recreating again. So my textview is getting collapsed. How can i prevent that the recreation of activity on orientation change. (But it should pick up the other layout file).

推荐答案

只需编辑活动代码在AndroidManifest.xml中。

Just edit the Activity Tag in androidmanifest.xml.

<activity
            android:configChanges="keyboardHidden|orientation"
            android:name=".testActivity"
            android:label="@string/app_name"></activity>

这篇关于安卓:停止重新创建活动的方向变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆