我正在試圖添加一個新的LinearLayout在我的opengl視圖之上由xml定義。addContentView到GLSurfaceView問題
public class VortexView extends GLSurfaceView {
public boolean onTouchEvent(final MotionEvent event) {
show_something();
}
void show_something()
{
//context is the main activity object that gets passed into this
LinearLayout ll = new LinearLayout(context);
b = new Button(context);
b.setText("hello world 1");
ll.addView(b);
ll.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
context.addContentView(ll, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
}
不過,我希望能夠做到這一點:
LinearLayout ll = (LinearLayout)findViewById(R.layout.main);
context.addContentView(ll, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
我的XML是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="kill"
/>
</LinearLayout>
每次我
我用純Java有這方面的工作儘管應用程序崩潰,請執行此操作。有任何想法嗎?