2012-08-07 3 views
3

Android 앱용 2D 게임 엔진을 만들려고합니다. 나는 this tutorial을 따라 왔는데, 이것은 전체 화면 디스플레이를 만드는 데는 잘 작동하지만, 나는 그것을 원하지 않는다. 내보기를 화면의 상단 2/3 (또는 무엇이든)으로 만들고 하단 Android 3 (단추, 텍스트 입력 등) 위젯을 채우고 싶습니다. 나는 이것을 작동시킬 수 없다. 내가 얻을 수있는 최선의 방법은 빈 화면입니다. 나는 바깥 쪽 LinerLayout을 사용하고 중첩 된 RelativeLayout 안에 사용자 정의 SurfaceView를 포함하고 중첩 된 LinearLayout에 안드로이드 위젯을 넣는 것을 포함하여 많은 순열을 시도했지만 작동하지 않습니다.Android 사용자 지정 크기 변경 SurfaceView

activity_main.xml :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:baselineAligned="false" > 

<RelativeLayout 
    android:layout_width="0dip" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/mapContainer" 
    > 
</RelativeLayout> 

<LinearLayout 
    android:layout_width="0dip" 
    android:layout_weight="1" 
    android:layout_height="0dp" 
    xmlns:android="http://schemas.android.com/apk/res/android" > 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:textColor="@color/white" 
     android:text="@string/test_str" /> 
</LinearLayout> 

</LinearLayout> 

MainActivity.java :

그것은 텍스트 뷰에 대한 50 %의 서피스 뷰 SurfaceView, 50 %이어야한다 같은 느낌 할 때 예를 들어

,이 흰색 화면을 생산

package com.removed.for.privacy; 

import com.removed.for.privacy; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.widget.LinearLayout; 
import android.widget.RelativeLayout; 
import android.widget.TextView; 

public class MainActivity extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     RelativeLayout mapContainer = (RelativeLayout) findViewById(R.id.mapContainer); 

     JSMapView mapView = new JSMapView(this); 
     mapContainer.addView(mapView); 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 
} 

아이디어가 있으십니까?

답변

7

인터넷 검색 및 준 관련 질문을 통해 알아 냈습니다. 다음은 세로 모드 (높이 100 %)에서 세로 2/3, 가로 2/3 (높이 100 %)를 채우는 방법의 예입니다. 추가,이 코드 클래스 생성자에서

@Override 
public void onLayout(boolean changed, int left, int top, int right, int bottom) { 
    if (changed) { 
     (this).layout(0, 0, viewWidth, viewHeight); 
    } 
} 

:

public YourCustomSurfaceView(Context context) { 
    super(context); 


    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 
    Display display = wm.getDefaultDisplay(); 
    int rotation = display.getRotation(); 

    // If vertical, we fill 2/3 the height and all the width. If horizontal, 
    // fill the entire height and 2/3 the width 
    if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) { 
     screenWidth = display.getWidth(); 
     screenHeight = display.getHeight(); 
     viewHeight = 2 * (screenHeight/3); 
     viewWidth = screenWidth; 
    } else { 
     screenWidth = display.getWidth(); 
     screenHeight = display.getHeight(); 
     viewWidth = 2 * (screenWidth/3); 
     viewHeight = screenHeight; 
    } 
    // Enter rest of code here 
} 
-1

은 서피스 뷰 SurfaceView의 사용자 정의 높이와 너비 사용 "android.view을 변경하려면를 사용자 정의 표면보기에서

는 onLayout 메소드를 오버라이드 (override) .ViewGroup.LayoutParams " ViewGroup의 여러 하위 클래스에 대한 LayoutParams의 하위 클래스가 있습니다. 예를 들어 AbsoluteLayout에는 X 및 Y 값을 추가하는 자체 LayoutParams 하위 클래스가 있습니다. 이것에 의하여 당신은 서피스 뷰 SurfaceView 높이 폭이 여기

코드 변경의 서피스 뷰 SurfaceView

의 X와 Y를 변경할 수 있습니다 http://agalaxycode.blogspot.in/2014/12/change-surfaceview-height-width.html

관련 문제