Android的方向变化 [英] Android Orientation Change
问题描述
我的标签式应用程序不会重新显示与方向变化的看法。
My tabbed app does not redisplay the view with an orientation change.
我添加
android:configChanges="keyboardHidden|orientation"
在主卡的活动,并在清单中各项活动。
to the main tab activity and to each activity in the manifest.
我添加到每个活动这个方法:
I added to each activity this method:
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setContentView(R.layout.active_alt);
mColorLegendBtn = (Button) findViewById(R.id.colorbtn);
mStatusView = (TextView) findViewById(R.id.celltitle1);
TextView mStatusView1 = (TextView) findViewById(R.id.celltitle2);
mStatusView1.setText(mStatusView1.getText()+"testcase1");
mStatusView.setText(mStatusView.getText()+"testcase");
initUI();
}
public void initUI() {
l1 = (ListView) findViewById(R.id.ListView01);
EfficientAdapter efficientAdapter = new EfficientAdapter(mContext);
l1.setAdapter(null);
l1.setAdapter(efficientAdapter);
}
在启动,标签,列表,按钮和TextView的正确显示。 当我改变方向在模拟器中,其他小部件仅显示标签没有,屏幕是黑的。
On launch, the tabs, list, button and textview are displayed correctly. When I change the orientation in the emulator, only the tabs are displayed none of the other widgets, the screen is black.
我在想什么?
推荐答案
我有完全相同这个问题。经过大量的试验和错误,我最终通过的一行变化到清单解决了这个问题。
I had exactly this problem. After much trial and error, I eventually solved it by making a one-line change to the manifest.
关键是要添加
android:configChanges="orientation|keyboardHidden"
你的 TabActivity
的清单中的条目。先不谈所有的子活动。甚至没有理会实施 onConfigurationChanged()
,甚至在 TabActivity
。
to your TabActivity
's entry in the manifest. Leave all the child activities alone. Don't even bother implementing onConfigurationChanged()
, not even in the TabActivity
.
我不知道为什么这似乎工作,但效果是布局被刷新,并且两个选项卡和子活动的内容是否正确,在新的方向重新绘制。
I don't know how or why this seems to work, but the effect is the layout is refreshed, and both the tabs and the child activity content are redrawn correctly in the new orientation.
这篇关于Android的方向变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!