2016-12-04 5 views
-2

В приведенном ниже коде я пытаюсь отобразить веб-просмотр после текстового просмотра. Веб-просмотр отображает, но текстовое представление, похоже, встроено в веб-просмотр, но не отображает.Как визуализировать текст перед веб-просмотром?

Код:

<?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 встроенный в WebView:

enter image description here

TextView было добавлено до WebView, так оно должно быть вынесено до WebView вместо в WebView?

Добавление 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> 

Update:

Используя 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

Как обернуть содержимое после текстового просмотра?

Update 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, вы должны поместить его после WebView в файле XML макет, как это:

<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

спасибо, но я пытаюсь отобразить текст перед веб-просмотром. –

+0

Вы должны включить «TextView» и 'WebView' в' LinearLayout'. – manfcas

+0

посмотрите пожалуйста обновление. –