2016-04-02 7 views
1

Ich entwickle meine erste android App und benutze Xamarin. Alles andere funktioniert gut, aber wenn ich aufgrund der Änderung der Auflösung zwischen verschiedenen Geräten umschalte, ändert sich die Position und Größe meiner UI-Elemente. Nachstehend ist der Main.xml-Code, den ich verwende.Wie kann man die Änderung der Position und Größe des UI-Elements mit der Änderung der Auflösung in Android vermeiden?

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/avsar_ui" 
     android:weightSum="100" 
     android:minWidth="200px" 
     android:minHeight="200px" 
     android:id="@+id/linearLayout1"> 
     <EditText 
      android:text="name" 
      android:textColor="?android:attr/searchWidgetCorpusItemBackground" 
      android:inputType="textPersonName" 
      android:layout_marginTop="225.0dp" 
      android:layout_marginBottom="25.0dp" 
      android:layout_width="match_parent" 
      android:background="@drawable/rounded_corner" 
      android:layout_marginLeft="50.0dp" 
      android:layout_marginRight="50.0dp" 
      android:layout_height="wrap_content" 
      android:id="@+id/PersonName" /> 
     <EditText 
      android:text="Contact Number" 
      android:textColor="?android:attr/searchWidgetCorpusItemBackground" 
      android:inputType="numberSigned" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/rounded_corner" 
      android:layout_marginLeft="50.0dp" 
      android:layout_marginBottom="10.0dp" 
      android:layout_marginRight="50.0dp" 
      android:id="@+id/ContactNumber" /> 
     <EditText 
      android:text="Address" 
      android:textColor="?android:attr/searchWidgetCorpusItemBackground" 
      android:inputType="textPostalAddress" 
      android:layout_width="match_parent" 
      android:background="@drawable/rounded_corner" 
      android:layout_marginLeft="50.0dp" 
      android:layout_marginRight="50.0dp" 
      android:layout_marginBottom="10.0dp" 
      android:layout_height="wrap_content" 
      android:id="@+id/Address" /> 
     <Spinner 
      android:layout_width="125.0dp" 
      android:background="@drawable/dropbox_bg" 
      android:layout_marginLeft="50.0dp" 
      android:layout_height="40.0dp" 
      android:id="@+id/Quantity" /> 
     <Button 
      android:background="@drawable/order_button" 
      android:layout_marginBottom="60dp" 
      android:layout_marginTop="100dp" 
      android:layout_marginLeft="115.0dp" 
      android:layout_marginRight="115.0dp" 
      android:layout_width="150.0dp" 
      android:layout_height="50.0dp" 
      android:id="@+id/OrderButton" /> 
    </LinearLayout> 

Antwort

0

Erstens - vermeiden px verwenden, wenn Sie skalierbare Layouts dp verwenden möchten. Zweitens - Sie testen wahrscheinlich Ihr Layout auf verschiedenen Bildschirmgrößen. Es gibt 4 Bildschirmgrößen in Android:

  • xlarge Bildschirme sind mindestens 960dp x 720dp
  • große Bildschirme sind mindestens 640dp x 480dp
  • normalen Bildschirme zumindest 470dp x 320dp
  • kleine Bildschirme sind mindestens 426dp x 320dp

enter image description here

So, während Ihr Layout gleich auf verschiedenen normalen Geräte aussehen wird, wird es kleiner auf große und xlarge Geräte, da ihre Bildschirme mehr dps haben. Möglicherweise möchten Sie separate Layouts für jede Bildschirmgröße angeben.

Weitere Informationen finden Sie in der Dokumentation Android Developers.

+0

geändert px zu dp dint help –

Verwandte Themen