我需要在代码中创建以下 xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:gravity="right"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#00000000"
>
<android.webkit.WebView android:layout_width="fill_parent"
android:id="@+id/adview"
android:scrollbars="none"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
></android.webkit.WebView>
<Button android:layout_width="wrap_content" android:text="x" android:textColor="#000000"
android:layout_height="wrap_content" android:id="@+id/hide_popup_button" android:background="#00000000"
android:layout_alignTop="@+id/adview" android:layout_alignParentRight="true"></Button>
</RelativeLayout>
我使用下面的代码,但我得到Force close
:
RelativeLayout popwindow=new RelativeLayout(this);
RelativeLayout.LayoutParams rl= new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 50);
popwindow.setLayoutParams(rl);
WebView w= new WebView(this);
w.setId(0X100);
w.setScrollContainer(false);
android.widget.RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)w.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
Button b=new Button(this);
b.setId(0X101);
b.setText("X");
b.setBackgroundColor(Color.TRANSPARENT);
b.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
android.widget.RelativeLayout.LayoutParams paramsbut = (RelativeLayout.LayoutParams)b.getLayoutParams();
paramsbut.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
paramsbut.addRule(RelativeLayout.ALIGN_TOP,w.getId() );
popwindow.addView(w,params);
popwindow.addView(b,paramsbut);
setContentView(popwindow);
我需要有关如何通过 java 代码制作该 xml 布局的建议。