Android转换为横向时,某些按钮不会显示

时间:2012-01-14 18:53:42

标签: android user-interface

我想知道如何在将视图转换为横向视图时显示相同的设计,任何人都可以帮助我。我尝试了这段代码,但它没有做任何事情

清单

android:configChanges="keyboardHidden|orientation"  

@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();
    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
}

@Override
public void setContentView(int layoutResID) 
{
    super.setContentView(layoutResID);
}

1 个答案:

答案 0 :(得分:1)

你是否在你的Manifest中将一个Activity减速器中的android:configChanges标志放入了?

尝试:

<activity android:name="myActivity" android:label="@string/app_name"
    android:configChanges="orientation">
</activity>

如果您不希望在设备旋转时更改布局,这应该足够了,而android将只重新计算并重新绘制视图。 如果您确实希望更改布局,则需要在onConfigurationChanged函数上加载不同的布局:

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    if (newConfig.orientation == android.content.res.Configuration.ORIENTATION_PORTRAIT)
    {
        setContentView(R.layout.portarit_view);
    }
    else if (newConfig.orientation == android.content.res.Configuration.ORIENTATION_LANDSCAPE)
    {
        setContentView(R.layout.landscape_view);
    }
}

顺便说一句,你可以在布局xml“图形布局”标签中预览它的外观。