2013-04-01 1 views
0

LayoutInflater를 사용하여 다른 xml 레이아웃에 하나의 xml 레이아웃을 추가하려고합니다. 하지만 표시되지 않습니다.Android에서 LayoutInflater를 사용하여 xml 레이아웃이 다른 xml 레이아웃에 표시되지 않습니다.

제 소스 코드를 확인하십시오.

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

당신의있는 ScrollView에 선 android:fillViewport="true"을 추가합니다. 트릭을해야합니다.

이 속성을 true로 설정하면 스크롤보기의 자식이 필요에 따라 ScrollView의 높이까지 확장됩니다. 아이가 ScrollView보다 큰 경우, 속성은 영향을주지 않습니다.

참고 : main_new.xml에있는 ScrollView를 둘러싼 RelativeLayout의를 제거해야

  1. 당신은 모두 불필요 row.xml

에 RelativeLayout의 주변의 LinearLayout을 제거해야