2016-11-18 1 views
0

안드로이드 장치에서 마이크로 컨트롤러 화면 (800x480)을 시뮬레이트하고 싶습니다. 화면 내용은 버튼, 레이블, 그래픽 프리미티브 (선, 사각형, ...), 이미지입니다. 모든 화면에 레이아웃 맞추기 (확대/축소)하려면 어떻게해야합니까?Android : 레이아웃 비례 배율

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:minWidth="800px" 
android:minHeight="480px" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/rootLayout" 
android:gravity="center"> 
<LinearLayout 
    android:orientation="horizontal" 
    android:minWidth="800px" 
    android:minHeight="480px" 
    android:layout_width="800px" 
    android:layout_height="480px" 
    android:id="@+id/mainContainer"> 
    <NSU.Droid.MyWindow 
     android:minWidth="714px" 
     android:layout_width="714px" 
     android:layout_height="match_parent" 
     android:id="@+id/mainWindow" 
     android:background="@drawable/window_shape" 
     android:layout_margin="1dp" /> 
    <LinearLayout 
     android:minWidth="86px" 
     android:layout_width="86px" 
     android:layout_height="match_parent" 
     android:background="@drawable/sidewindow_shape" 
     android:layout_margin="1px" 
     android:scrollbars="none"> 
    <ScrollView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <NSU.Droid.SideWindow 
      android:orientation="vertical" 
      android:minWidth="86px" 
      android:layout_width="86px" 
      android:layout_height="wrap_content" 
      android:id="@+id/sideWindow" 
      android:scrollbars="none" /> 
    </ScrollView> 
    </LinearLayout> 
</LinearLayout> 

NSU.Droid.MyWindow이 RelativeLayout의이다 :

다음은 레이아웃 XML입니다.
px를 사용하면 시뮬레이션 된 레이아웃이 너무 작아서 장치 화면에서 약 1/3입니다. px를 dp로 변경해도 도움이되지 않습니다.보기가 너무 크면 레이아웃 내용의 약 2/3을 볼 수 있습니다.
레이아웃과 내용의 크기를 비례하여 조정하는 방법은 무엇입니까?

답변

0

android:layour_width 또는 android:layout_height 속성에 match_parent 속성을 사용하여 레이아웃이있는 화면에 맞 춥니 다. 항목 크기를 비례하게 만들려면 에 android:layout_weight 속성을 사용할 수 있습니다. 예를 들어

:

<LinearLayout 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    android:orientation="horizontal"> 
    <FrameLayout android:layout_width="0dp" android:layout_height="match_parent" 
     android:background="#ff0000" 
     android:layout_weight="3" /> 
    <FrameLayout android:layout_width="0dp" android:layout_height="match_parent" 
     android:background="#0000ff" 
     android:layout_weight="1" /> 
</LinearLayout> 

당신이 당신의 LinearLayout 가로 방향이있는 경우

, 당신은 설정해야 android:layout_width 0dp에 속성을 당신이 android:layout_weight 특성을 적용하려는이 LinearLayout의 요소. LinearLayout의 방향이 수직 인 경우 android:layout_height 속성을 0dp으로 설정해야합니다. 위의

XML은 다음과 같아야합니다

Weights

+0

콘텐츠 생성 런타임입니다. 나는 마이크로 컨트롤러 UI 파일을 읽고 RelativeLayout 내부에서 뷰 런타임을 생성하고 크기를 픽셀 단위로 지정하고있다. 그래서 크기가 고정 된 레이아웃 - 800x480px (ImageViews, Buttons, TextViews 포함). 이제는 더 크거나 작은 사용 가능한 공간을 비례 적으로 채우기 위해이 레이아웃을 내용으로 확장해야합니다. 이 작업을 수행하는 방법? – Bixit