2011-12-06 1 views

답변

2

당신은 화면 크기를 얻을 시도 할 수 있습니다 :

Display display = getWindowManager().getDefaultDisplay(); 
    int width = display.getWidth(); 
    int height = display.getHeight(); 

와 방향 :

public int getScreenOrientation() { 
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { 
     return 1; // Portrait Mode 
    }else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { 
     return 2; // Landscape mode 
    } 
    return 0; 
} 
0

시도 레이아웃 픽셀의 수정 양을 피하기 위해. 파 예를 들어,이 코드는 화면과 같은 폭으로 두 개의 버튼, 각각의 절반을 그릴 것입니다 :

<LinearLayout 
    android:id="@+id/Tab1_Buttonline1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <Button 
     android:id="@+id/function_datasync" 
     android:layout_width="wrap_content" 
     android:text="Daten Sync" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_margin="5dip" 
     android:textAppearance="?android:attr/textAppearanceLargeInverse" 
     android:maxLines="1"> 
    </Button> 
    <Button 
     android:id="@+id/function_docsync" 
     android:layout_width="wrap_content" 
     android:text="Datei Sync" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:layout_margin="5dip" 
     android:textAppearance="?android:attr/textAppearanceLargeInverse" 
     android:maxLines="1"> 
    </Button> 
</LinearLayout> 

또한 드로어 블-hdpi에/-mdpi 또는 -ldpi foders를저기서에 의해 서로 다른 해상도에 대해 서로 다른 레이아웃을 정의 할 수 있습니다, 서로 다른 드로어 블을 정의 할 수 있습니다.

컨트롤의 특정 높이 또는 무게를 사용하도록 강요당한 경우 (예 :

android:layout_margin="5dip" 

"딥"때문에 여백이 모든 해상도에서 비슷하게 나타납니다.

관련 문제