0

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>
4

1 に答える 1

0

android:fillViewport="true"ScrollViewに行を追加します。それはトリックを行う必要があります。

この属性を true に設定すると、必要に応じて、スクロール ビューの子が ScrollView の高さまで拡張されます。子が ScrollView よりも背が高い場合、属性は効果がありません。

ノート :

  1. main_new.xml で ScrollView を囲む RelativeLayout を削除する必要があります。
  2. row.xml で RelativeLayout を囲む LinearLayout を削除する必要があります。

どちらも不要

于 2013-04-11T11:43:23.027 に答える