主要活动和片段中包含webview的Android应用程序[activity2:HeaderActivity]

时间:2015-02-26 09:52:46

标签: android webview fragment

我希望显示具有webview的MainActivity(webview已经在MainActivity中),并且片段显示为Activity2。这里是代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">

<fragment
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:name="chronical.com.sayc.HeaderFragment"
    android:id="@+id/fragment"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    tools:layout="@layout/activity_header_fragment" />

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     />
</LinearLayout>

问题是它没有显示HeaderActivity。当应用程序启动时,它只显示webview。

2 个答案:

答案 0 :(得分:0)

您的网络浏览量高度为match_parent

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
 />

请更改webview的高度

并设置线性布局方向

机器人:取向=&#34;垂直&#34;

答案 1 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:weightSum="1" >

    <fragment
        android:id="@+id/fragment"
        android:name="chronical.com.sayc.HeaderFragment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_weight="0.2"
        tools:layout="@layout/activity_header_fragment" />

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.8" />

</LinearLayout>

You can use the **android:layout_weight** property to divide your parent view depending on the weight of its child view like for example 20% of your parent view will be covered by fragment and 80% by the WebView.