2013-04-01 2 views
0

Я пытаюсь добавить один макет xml в другой макет xml с помощью LayoutInflater. но его не показывается.xml макет не отображается в другом макете xml с использованием LayoutInflater в Android

Проверьте исходный код.

import android.app.Activity; 
import android.content.Context; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.webkit.WebView; 
import android.widget.RelativeLayout; 

public class CustomeWebView extends Activity { 
RelativeLayout relLay; 
WebView webview; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main_new); 
    relLay = (RelativeLayout) findViewById(R.id.main_relLay); 
    LayoutInflater inflater = (LayoutInflater) getApplication() 
      .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View v_child = inflater.inflate(R.layout.row, null); 
    relLay.addView(v_child); 
} 
} 

основной XML файл

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<ScrollView 
    android:id="@+id/scrollview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <RelativeLayout 
     android:id="@+id/main_relLay" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#0B7A3B" > 
    </RelativeLayout> 
</ScrollView> 

</RelativeLayout> 

ребенок XML файл

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

<RelativeLayout 
    android:id="@+id/row_relLay" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#F70925"> 

    <WebView 
     android:id="@+id/row_webView" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:visibility="gone"> 
    </WebView> 
</RelativeLayout> 

</LinearLayout> 
+0

Изменить видимость веб-просмотра на видимую. –

+0

ОК я попробую ... –

+0

ничего ... его показ пустой белый экран ... –

ответ

0

Добавьте строку android:fillViewport="true" к вашему ScrollView. Это должно сделать трюк.

Если установлено значение true, этот атрибут заставляет дочерний элемент прокрутки расширяться до высоты ScrollView, если это необходимо. Когда ребенок выше, чем ScrollView, атрибут не действует.

Примечание:

  1. Вы должны удалить RelativeLayout окружающего ваш Scrollview в main_new.xml
  2. Вы должны удалить LinearLayout окружающего ваш RelativeLayout в row.xml

Оба являются ненужными