问题描述
我一直在研究stackoverflow中的问题,我已经尝试了所见过的一切,但是版图设计却无法正常工作.在我的代码中,我有方法 onConfigurationChanged
I've been looking at issues in stackoverflow and I've tried everything I've seen but the layout-land not work.In my code I have and the method onConfigurationChanged
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
清单文件:
<activity
android:name="com.sde.PlayerTrack"
android:theme="@style/AppTheme"
android:configChanges="orientation|keyboardHidden|screenSize"
>
</activity>
我也尝试在android清单条目中删除:configChanges,然后布局加载,但是我拥有的组件(TextView,滚动条...)无法正常工作.
I tried also to remove in the android manifest entry: configChanges and then the layout land load but the components i have (TextView, scrollbar ...) does not work properly.
可以帮我吗?
推荐答案
最后,我的解决方法是:
Finally, my solution is:
AndroidManifest.xml文件:
AndroidManifest.xml File:
<activity
android:name="activity.name"
android:configChanges="orientation|keyboardHidden|screenSize"
>
并在活动中实现onConfigurationChanged(配置newconfig)方法:
And in the activity implement the method onConfigurationChanged (Configuration newconfig):
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
createHorizontalalLayout();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
createVerticalLayout();
}
}
使用createVerticalLayout()和createHorizontalLayout()以编程方式进行布局.
With createVerticalLayout () and createHorizontalLayout () programmatically do the layouts.
这篇关于Android布局土地无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!