-1

我正在开发这个在 webview 中检索网页的 android 应用程序,我在屏幕顶部有这个横幅。它在纵向布局中并不明显,但在横向布局中,它几乎占据了屏幕的上半部分。

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/header"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#EAC117"
        android:textSize="35sp" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@raw/firstintentlogo"
        android:layout_weight="1" android:contentDescription="@string/headLogoName"/>



 </LinearLayout> 

我不知道在java文件中“当手机处于横向模式时,隐藏这个linearLayout”。

有什么建议么?

4

3 回答 3

3

在您的活动中覆盖 onConfigurationChanged

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
    {
        //TODO
    }
    super.onConfigurationChanged(newConfig);
}
于 2013-09-13T20:15:28.347 回答
2

如果您自己处理更改,则可以将其添加onConfigurationChanged()到 set that Layout's visibilityto gone

如果您让操作系统处理配置更改,那么您可以layouts根据方向创建分离。您将layoutfor Portrait 放在layout文件夹中,然后创建另一个名为的文件夹,layout-land以便操作系统知道layout在设备处于 Landscape 时使用该文件夹中的orientation

使用配置限定符

在大多数情况下,文档不建议手动处理配置更改

允许系统处理配置更改

于 2013-09-13T20:14:11.653 回答
1

尝试这个

@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        //check config
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
    linearLayout.setVisibility(View.GONE); //set visibility of linearLayout as Gone
    Toast.makeText(this, "mode landscape", Toast.LENGTH_SHORT).show();
    }

    }

希望这有效

于 2013-09-13T20:14:57.627 回答