2017-07-25 1 views
-3

Ich bin ein Anfänger auf Android-App-Entwicklung und ich habe ein Problem, das ich keine Lösung finden kann. Ich arbeite die App auf Nexus 5 und es funktioniert perfekt, keine Leerräume zwischen Layouts, aber wenn ich zu nexus Schaltern 4, das ist, was passiert, (i Farben verwenden die Layouts zu trennen):Android - Rechner unterstützt alle Bildschirmgrößen

https://scontent.fath3-1.fna.fbcdn.net/v/t34.0-12/20403684_1379424475444386_454511879_n.jpg?oh=440d7b9ab5670c8cad87133475ec0cb6&oe=5979CDED


, wenn ich auf die Pixel xl wechseln:

https://scontent.fath3-1.fna.fbcdn.net/v/t34.0-12/20403737_1379426118777555_859609190_n.jpg?oh=61ccd01da7a4470491fb4125da8db43c&oe=597996E4

Was kann ich tun, so dass es keine leeren Räume auf der rechten Seite haben (unten gibt es XML-Code gepostet nur, wenn Sie es brauchen) .

<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:background="@android:color/black" 
android:orientation="vertical" 
android:weightSum="1"> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#f00"> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:onClick="onClickDTB" 
      android:text="Convert to Binary" 
      android:textAlignment="center" 
      android:textAllCaps="true" 
      android:textSize="14sp" 
      android:textStyle="bold|italic" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#0f0"> 

     <TextView 
      android:id="@+id/textView" 
      android:layout_width="match_parent" 
      android:layout_height="98dp" 
      android:layout_weight="0.01" 
      android:fontFamily="serif-monospace" 
      android:text="Calculator" 
      android:textAlignment="textEnd" 
      android:textColor="@android:color/white" 
      android:textSize="35dp" 
      android:textStyle="bold" /> 
    </LinearLayout> 


<LinearLayout 


    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:background="#f0f" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:layout_width="72.4dp" 
     android:layout_height="match_parent" 
     android:background="#FFA500" 
     android:orientation="vertical"> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="72.4dp" 
     android:layout_height="match_parent" 
     android:background="#000FFF" 
     android:orientation="vertical"> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="72.4dp" 
     android:layout_height="match_parent" 
     android:background="#8B0000" 
     android:orientation="vertical"> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="72.4dp" 
     android:layout_height="match_parent" 
     android:background="#800080" 
     android:orientation="vertical"> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="72.4dp" 
     android:layout_height="match_parent" 
     android:background="#2E8B57" 
     android:orientation="vertical"> 

    </LinearLayout> 


</LinearLayout> 

+0

https://developer.android.com/ guide/practices/screens_support.html https://developer.android.com/training/multiscreen/screensizes.html – Nenco

+0

Verwenden Sie Gewicht und Gewicht Summe Eigenschaft für Sie Layout –

+0

Ich habe jeden verfügbaren Link gesehen und ich habe es versucht, aber es scheint, dass es nicht funktioniert. Deshalb habe ich gefragt, dass ich jemanden brauche, um das Problem basierend auf meinem Code zu erklären, damit ich verstehe, was im Allgemeinen passiert. –

Antwort

0

Sie müssen Gewicht und Gewicht Summe wie diese

verwenden
<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:background="@android:color/black" 
    android:orientation="vertical" 
    android:weightSum="1"> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#f00"> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:onClick="onClickDTB" 
      android:text="Convert to Binary" 
      android:textAlignment="center" 
      android:textAllCaps="true" 
      android:textSize="14sp" 
      android:textStyle="bold|italic" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#0f0"> 

     <TextView 
      android:id="@+id/textView" 
      android:layout_width="match_parent" 
      android:layout_height="98dp" 
      android:layout_weight="0.01" 
      android:fontFamily="serif-monospace" 
      android:text="Calculator" 
      android:textAlignment="textEnd" 
      android:textColor="@android:color/white" 
      android:textSize="35dp" 
      android:textStyle="bold" /> 
    </LinearLayout> 


    <LinearLayout 


     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#f0f" 
     android:weightSum="100" 
     android:orientation="horizontal"> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_weight="20" 
      android:layout_height="match_parent" 
      android:background="#FFA500" 
      android:orientation="vertical"> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_weight="20" 
      android:layout_height="match_parent" 
      android:background="#000FFF" 
      android:orientation="vertical"> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="20" 
      android:background="#8B0000" 
      android:orientation="vertical"> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_weight="20" 
      android:layout_height="match_parent" 
      android:background="#800080" 
      android:orientation="vertical"> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="20" 
      android:background="#2E8B57" 
      android:orientation="vertical"> 

     </LinearLayout> 


    </LinearLayout> 
    </LinearLayout> 
+0

oh, ich sehe ... die gleiche Antwort, was bedeutet, es ist der Weg, es zu tun –

+0

Ja Layout Gewicht wird teilen Sie Eltern Layout zu 5 Portionen, die Sie Bildschirm vollständig abdecken und keine richtigen Platz übrig. –

+0

Vielen Dank beide, es funktioniert tatsächlich. –

0

unten Code Versuchen

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#f00"> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:onClick="onClickDTB" 
     android:text="Convert to Binary" 
     android:textAlignment="center" 
     android:textAllCaps="true" 
     android:textSize="14sp" 
     android:textStyle="bold|italic" /> 

</LinearLayout> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#0f0"> 

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="match_parent" 
     android:layout_height="98dp" 
     android:layout_weight="0.01" 
     android:fontFamily="serif-monospace" 
     android:text="Calculator" 
     android:textAlignment="textEnd" 
     android:textColor="@android:color/white" 
     android:textSize="35dp" 
     android:textStyle="bold" /> 
</LinearLayout> 


<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#f0f" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#FFA500" 
     android:orientation="vertical"> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#000FFF" 
     android:orientation="vertical"> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#8B0000" 
     android:orientation="vertical"> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#800080" 
     android:orientation="vertical"> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:background="#2E8B57" 
     android:orientation="vertical"> 

    </LinearLayout> 


</LinearLayout> 
+0

, so dass Sie tatsächlich Layout_weight zu allen Layouts hinzugefügt? –

+0

Ja @ A.Tressos, müssen Sie hinzufügen, wenn es mit allen Bildschirmgrößen passt. –

Verwandte Themen