2012-05-26 4 views
0

이미이 질문을 Relative layout Coding에 요청했지만이 시도는 확실하지 않았습니다.OpenGL 및 Android 관련 레이아웃

나는 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> 

그러나, 나는 그것을 코딩하는 경우가 작동 답을 말처럼하지만 이미지가 여전히 넣어 서로의 상단. (나는 getld 함수를 addrules에 사용했다.)

그래서 전체 XML 파일을 추가하고 그런 식으로 작업 할 생각이지만 xml을로드하면 app이 멈춘다. 마음에 마지막 호출하지 않고 addContentView 앱 작동

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)); 

곰 : 여기에 대부분의 코드입니다.

+0

내 자신의 질문에 답변 할 것 같습니다. addcontentview 대신 다음을 추가했습니다. gi = new RelativeLayout (this); 보기보기; LayoutInflater inflater = (LayoutInflater) getApplicationContext(). getSystemService (Context.LAYOUT_INFLATER_SERVICE); view = inflater.inflate (R.layout.gi, null); hud.addView (보기); \t \t addContentView (gi, new ViewGroup.LayoutParams (ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT)); – user1398593

+0

그리고 그와 같이 glsurface 뷰 위에 전체 XML 파일을 추가하는 데 성공했습니다. 하지만 지금은 r.layout.gi에서 각 어린이의 ID를 얻는 방법에 대해 궁금합니다. R.id.imageView1의 그림을 바꾸고 싶다고하자. ?????????????? (특별 감사 http://stackoverflow.com/questions/2335813/how-to-inflate-one-view-with-an-layout) – user1398593

+1

댓글은 답변이 아닙니다. 자신의 질문에 대답하고 싶다면 실제로 페이지 하단의 "답변 게시"버튼을 사용하여 * 대답 *하십시오. –

답변

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)); 

을 첨가하고, 같은 I는 glsurface 뷰 상기 전체 XML 파일을 추가로 succeded.

그러나 r.layout.gi에서 각 어린이의 ID를 얻는 방법에 대해 궁금합니다. R.id.imageView1의 그림을 바꾸고 싶다고하자. ??????????????

아무도 현재 코드로이를 수행하는 방법을 알고 있습니까?

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));