2016-11-18 1 views
0

Ich möchte Microcontroller Bildschirm (800x480) auf Android-Geräten zu simulieren. Der Bildschirminhalt besteht aus Schaltflächen, Beschriftungen, grafischen Grundelementen (Linie, Rechteck, ...) und Bildern. Was ist zu tun, um das Layout (auf/ab) auf allen Bildschirmen anzupassen?Android: Layout proportionale Skala

Hier ist das Layout 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 ist RelativeLayout.
Wenn px verwendet wird, ist das simulierte Layout zu klein, etwa 1/3 auf meinem Gerätebildschirm. Das Ändern von px nach dp hilft nicht - die Ansicht ist zu groß, ich kann ungefähr 2/3 des Layout-Inhalts sehen.
Wie werden Layout und Inhalt proportional skaliert?

Antwort

0

Verwenden Sie für android:layour_width oder android:layout_height Attribute, um Bildschirm mit Layout anzupassen. Um Artikelgrößen proportional zu machen, können Sie das Attribut android:layout_weight in LinearLayout verwenden.

Zum Beispiel:

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

Wenn Sie horizontale Ausrichtung Ihres LinearLayout haben, sollten Sie setzen android:layout_width Attribut 0dp auf Elemente dieser LinearLayout, zu dem Sie android:layout_weight Attribut anwenden möchten. Wenn Ihre Ausrichtung LinearLayout vertikal ist, dann sollte android:layout_height Attribut auf 0dp festgelegt werden.

Die XML oben sollte wie folgt aussehen:

Weights

+0

Inhalt ist erstellt Laufzeit. Ich lese Mikrocontroller-UI-Datei und Erstellen von Ansichten Runtime in RelativeLayout, Angabe der Größe in Pixel. Also habe ich ein festes Größenlayout - 800x480px (mit ImageViews, Buttons, TextViews). Und jetzt muss ich dieses Layout mit Inhalt skalieren, um den verfügbaren Platz zu füllen, größer oder kleiner, proportional. Wie macht man das? – Bixit

Verwandte Themen