我如何使元素标记调整为屏幕从potrait切换到android
问题描述:
我想知道如何在两个方向之间切换时实现此目的。我尝试使用保证金或centerVertical,但只会保持在中心,不可调整。我如何使元素标记调整为屏幕从potrait切换到android
请大家帮忙。 谢谢。
答
创建布局,土地目录和设计横向模式的设计在此目录中和肖像模式保持设计相同布局目录。这将很容易帮助管理风景和肖像不同的设计。
像这样:
res/layout-land [Landscape Mode]
main.xml
res/layout-port [Portrait Mode ]
main.xml
在的Manifest.xml加方向配置的变化对您的活动标签
android:configChanges="orientation"
我们设置XML内容到你的活动覆盖onConfigurationChanged方法并将内容是这样的:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
setContentView(R.layout.main);//This main.xml is in layout-land folder
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
setContentView(R.layout.main);//This main.xml is in layout folder
}
}
你是什么意思调整? –
检查此http://code.hootsuite.com/orientation-changes-on-android/教程。 –