我想将视图添加到我的主视图中。。。。
我的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>
我想将此web视图添加到linearlayout中。。。。这意味着我想将网络视图扩展到我的主要活动中。。。
我使用了以下方法。。。
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);
但这行不通。如果这是正确的,那么颜色必须改变。。。但什么也没发生。请帮帮我…我受够了。。。
感谢
试试这个:
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);
您试图更改已由WebView
填充的FrameLayout
的颜色,因此绿色将不可见。相反,您必须更改WebView
的颜色。