0

私はすでに相対レイアウトコーディングでこの質問をしようとしましたが、その最初の試みはあまり明確ではありませんでした。

相対レイアウトを作成したいのですGLSurfaceViewが、レイアウトは次のようになっている必要があります。

<RelativeLayout
        android:id="@+id/View1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@raw/gi"
        android:orientation="vertical" >

        <ImageView
                android:id="@+id/imageView1"
                android:layout_width="64px"
                android:layout_height="64px"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:src="@drawable/b1" />

        <ImageView
                android:id="@+id/imageView2"
                android:layout_width="64px"
                android:layout_height="64px"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/imageView1"
                android:src="@drawable/b2" />

        <ImageView
                android:id="@+id/imageView3"
                android:layout_width="64px"
                android:layout_height="64px"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/imageView2"
                android:src="@drawable/b3" />
</RelativeLayout>

しかし、私が彼らが答えで言うようにそれをコーディングすると、それは機能しますが、画像はまだお互いの上に置かれています。(getId関数を使用してルールを追加しました)

だから私はxmlファイル全体を追加してそのように動作することを考えていますが、xmlをロードするたびにアプリが停止します。ほとんどのコードは次のとおりです。

public class HelloWorld extends Activity {
...
protected void onCreate(Bundle savedInstanceState) {
    ....
    opengl = new GLSurfaceView(getApplication());
    opengl.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
        public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
              int[] attributes = new int[] { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE};
              EGLConfig[] configs = new EGLConfig[1];
              int[] result = new int[1];
              egl.eglChooseConfig(display, attributes, configs, 1, result);
              return configs[0];
        }
    });

    renderer = new MyRenderer();
    mGLView.setRenderer(renderer);
    setContentView(opengl);
    addContentView(findViewById(R.id.View1), new RelativeLayout.LayoutParams(
              RelativeLayout.LayoutParams.FILL_PARENT,
              RelativeLayout.LayoutParams.FILL_PARENT));

addContentViewアプリへの最後の呼び出しがなくても機能することを覚えておいてください。

4

2 に答える 2

0

私自身の質問に答えるつもりのようです。

addcontentview の代わりに、次を追加しました

gi=new RelativeLayout(this);
                View view; 
        LayoutInflater inflater = (LayoutInflater)   getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        view = inflater.inflate(R.layout.gi, null);
        hud.addView(view);
        addContentView(gi, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));

そのため、glsurface ビューの上に xml ファイル全体を追加することに成功しました。

しかし、r.layout.giで各子のIDを取得する方法について今疑問に思っています。R.id.imageView1 の写真を変更したいとしましょう??????????????

現在のコードでこれを行う方法を知っている人はいますか?

于 2012-05-26T21:41:22.700 に答える
0

これが通常のFrameLayoutでうまくいったことを私は知っています。

    TextView counter = new TextView(getApplicationContext());
    counter.setBackgroundResource(R.drawable.counter);
    counter.setTextSize(50);
    counter.setTypeface(null, Typeface.BOLD);
    counter.setText(" 000");
    addContentView(counter, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
于 2015-10-04T20:46:21.340 に答える