我正在尝试获取标题“54dp”,其余的活动是 WebView。
当我在 eclips 的“图形布局”中预览我的活动时,它看起来不错。但是当在手机或模拟器上运行应用程序时,webview 会占据整个屏幕。
这就是预览的样子和我想要的样子:
但这是我在运行应用程序时看到的:
这是布局 xml 的样子:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/page_background"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/Layout_Header"
android:layout_width="fill_parent"
android:layout_height="54dp"
android:orientation="horizontal"
android:background="@drawable/container_header"
android:paddingLeft="16dp"
android:paddingRight="16dp"
>
<ImageView
android:id="@+id/imgHeaderLogo"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="46dp"
android:contentDescription="@string/img_header_logo_description"
android:src="@drawable/header_logo"
android:layout_gravity="center"
/>
</LinearLayout>
<WebView android:id="@+id/web_engine"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
解决方案:
在活动java文件中我有这个:
WebView browser = (WebView) findViewById(R.id.web_engine);
WebSettings webSettings = browser.getSettings();
setContentView(browser);
当我应该有这个时:
setContentView(R.layout.activity_sign_in_web_view);