2016-12-04 59 views
-2

在下面的代碼中,我試圖在textview之後呈現webview。 webview呈現,但textview似乎嵌入在webview中,但不呈現。如何在webview之前渲染textview?

代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.sum.MainActivity"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello" /> 

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context=".MainActivity"> 
     tools:ignore="MergeRootFrame"> 

     <WebView 
      android:id="@+id/activity_main_webview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 
    </FrameLayout> 

</RelativeLayout> 

TextView的嵌入式網頁視圖中:

enter image description here

TextView的前已經向web視圖增加,所以應該web視圖之前,而不是在網頁視圖中呈現?

添加的TextView到FrameLayout裏不也呈現TextView的:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 
    tools:ignore="MergeRootFrame"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello" /> 
    <WebView 
     android:id="@+id/activity_main_webview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</FrameLayout> 

更新:

使用LinearLayout中呈現的TextView但Webview是不渲染TextView的下方,而不是它的呈現到右:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.example.sum.MainActivity"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello" 
     android:paddingBottom="5dp" 
     /> 

     <WebView 
      android:paddingTop="5dp" 
      android:id="@+id/activity_main_webview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

</LinearLayout> 

enter image description here

如何在textview後包裝內容?

更新2:

這工作:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:orientation="vertical" 
    tools:context="com.example.sum.MainActivity"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello" 
     android:paddingBottom="5dp" 
     /> 

     <WebView 
      android:paddingTop="5dp" 
      android:id="@+id/activity_main_webview" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

</LinearLayout> 

回答

0

如果你想TextView要顯示在WebView,你應該把它放在你的佈局XML文件中的WebView後,像這樣:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity"> 

    <WebView 
     android:id="@+id/activity_main_webview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello" /> 

</FrameLayout> 
+0

謝謝,但我試圖呈現webview之前的textview –

+0

你必須包括'TextView'和'LinearLayout'中的'WebView'。 – manfcas

+0

請參閱更新。 –