安卓:停止重新创建活动的方向变化创建活动、方向

2023-09-12 22:24:49 作者:我想給妳我全部的疼愛

我有我的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>