2

我想将视图添加到我的主视图中......

我的 main.xml 文件...

<LinearLayout
        android:id="@+id/dynamicview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1.28"
        android:gravity="center_vertical"
        android:orientation="vertical" >

</LinearLayout>

我有另一个布局文件调用 complete.xml

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

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

</FrameLayout>

我想将此网页视图添加到线性布局中......这意味着我想将网页视图膨胀到我的主要活动中......

我使用了以下方法...

LinearLayout dynamic=(LinearLayout)findViewById(R.id.dynamicview);
LayoutInflater inflater = (LayoutInflater)    getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View v = (FrameLayout) inflater.inflate(R.layout.complete, null);
        v.setBackgroundColor(Color.GREEN);
        v.getRootView();
        dynamic.addView(v);
        v.setVisibility(View.VISIBLE);

但这不起作用。如果这是正确的,那么颜色必须改变......但什么也没发生。请帮助我..我坚持这个...

谢谢

4

1 回答 1

0

尝试这个:

LinearLayout dynamic=(LinearLayout)findViewById(R.id.dynamicview);
LayoutInflater inflater = (LayoutInflater)    getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View v = (FrameLayout) inflater.inflate(R.layout.complete, null);

WebView wv = (WebView)v.findViewById(R.id.webView1);
wv.setBackgroundColor(Color.GREEN);
        v.getRootView();
        dynamic.addView(v);
        v.setVisibility(View.VISIBLE);

您试图更改FrameLayout已填充的颜色,WebView因此绿色将不可见。相反,您必须更改WebView.

于 2013-08-11T07:44:14.900 回答