2016-11-18 4 views
0

私はアンドロイドデバイスでマイクロコントローラの画面(800x480)をシミュレートしたいと思います。画面内容は、ボタン、ラベル、グラフィックプリミティブ(線、矩形、...)、画像です。 すべての画面でレイアウトを調整するにはどうすればよいですか?ここでAndroid:レイアウト比例スケール

はレイアウトxmlです:

<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です。
pxを使用すると、シミュレートされたレイアウトが小さすぎます(デバイスの画面で約1/3)。 pxをdpに変更しても表示が大きくなりません。レイアウトの内容の2/3を見ることができます。
レイアウトとコンテンツを比例配分する方法は?

答えて

0

android:layour_widthまたはandroid:layout_heightの属性にmatch_parentを使用して、レイアウトに合わせて画面に合わせます。 アイテムのサイズを比例させるには、android:layout_weight属性をLinearLayoutに使用できます。例えば

<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

関連する問題