2016-08-05 8 views
1

Ich versuche Texteingabekomponenten mit der Größe des Bildschirms übereinstimmen. Zum Beispiel möchte ich so aussehen. ThisRaster-Layout-Elemente, um die übergeordnete Größe anzupassen

jedoch, wenn die Größe des Bildschirms größer ist, ist das, was ich bekomme. This

Also, hier ist mein Code.

<GridLayout 
    android:layout_below="@+id/TopBarLayout" 
    android:layout_above="@+id/BottomBarLayout" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_centerVertical="true" 
    android:gravity="center" 
    android:padding="30dp" 
    android:id="@+id/PatientLayout" 
    android:rowCount="6" 
    android:columnCount="1"> 
    <EditText 
     style="@style/Editor" 
     android:layout_width="match_parent" 
     android:id="@+id/PatientFirstNameEditText" 
     android:hint="@string/FirstNameHint" 
     android:layout_row="0" 
     android:layout_column="0" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp" /> 
    <EditText 
     style="@style/Editor" 
     android:layout_width="match_parent" 
     android:id="@+id/PatientLastNameEditText" 
     android:hint="@string/LastNameHint" 
     android:layout_row="1" 
     android:layout_column="0" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp" /> 
    <EditText 
     style="@style/Editor" 
     android:layout_width="match_parent" 
     android:id="@+id/PatientMiddleNameEditText" 
     android:hint="@string/MiddleNameHint" 
     android:layout_row="2" 
     android:layout_column="0" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp" /> 
    <LinearLayout 
     android:id="@+id/TopBarLayout" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent" 
     android:orientation="horizontal" 
     android:layout_weight="100" 
     android:background="#e8e8f5" 
     android:layout_row="3" 
     android:layout_column="0" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp"> 
     <EditText 
      android:inputType="date" 
      style="@style/Editor" 
      android:id="@+id/DateOfBirthEditText" 
      android:layout_weight="90" 
      android:layout_width="0dp" /> 
     <ImageButton 
      android:src="@drawable/calendar" 
      android:layout_height="match_parent" 
      android:layout_width="0dp" 
      android:layout_weight="10" 
      android:id="@+id/ShowDatePickerButton" 
      android:background="@android:color/transparent" 
      android:layout_marginTop="5.0dp" 
      android:layout_marginBottom="5.0dp" /> 
    </LinearLayout> 
    <EditText 
     style="@style/Editor" 
     android:layout_width="match_parent" 
     android:id="@+id/PatientSocialSecurityNumberEditText" 
     android:hint="@string/SocialSecurityNumberHint" 
     android:layout_row="4" 
     android:layout_column="0" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp" /> 
    <RadioGroup 
     android:id="@+id/TopBarLayout" 
     android:padding="10dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_row="5" 
     android:layout_column="0" 
     android:orientation="horizontal" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="10dp"> 
     <RadioButton 
      android:text="@string/Male" 
      android:padding="10dp" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:id="@+id/PatientMaleRadioButton" 
      android:checked="true" /> 
     <RadioButton 
      android:text="@string/Female" 
      android:padding="10dp" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:id="@+id/PatientFemaleRadioButton" /> 
    </RadioGroup> 
</GridLayout> 

Ich habe Ränder eingestellt, so dass es 5inch Bildschirm übereinstimmen würde. Ich möchte Komponenten an die Größe des Bildschirms anpassen. Wenn beispielsweise der Bildschirm klein ist, sollte der Text ebenfalls proportional kleiner sein. Ich möchte das gleiche Ergebnis von Rasterlayout als von der Grid-Panel von C# winform erhalten. Danke!

+0

Haben Sie versucht, mehrere XML-Dateien zu verwenden, um verschiedene Bildschirmgrößen zu unterstützen? –

+1

Und warum verwenden Sie Rasterlayout, um einzelne Spalten anzuzeigen? Warum gehst du nicht für LinearLayout? –

Antwort

1

Da alles, was Sie erstellen möchten, in einer Spalte Ihres Rasters liegt, können Sie ein vertikales lineares Layout für die äußeren und inneren Editiertexte und ein horizontales lineares Layout für die zwei Optionsfelder verwenden. Sie können android:layout_weight verwenden, um die Elemente als Prozentsatz der Seite festzulegen. Sie können auch mit android:layout_margin spielen, um ihre Ränder genauer zu ändern, es gibt auch marginTop/Bottom/Right etc. Hope this helps.

<?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="#000000 "> 


    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:id="@+id/editText1" 
     android:layout_margin="20dp" 
     android:background="#ffffff " 
     android:layout_gravity="center_horizontal" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:id="@+id/editText2" 
     android:layout_margin="20dp" 
     android:background="#ffffff " 
     android:layout_gravity="center_horizontal" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:id="@+id/editText3" 
     android:layout_margin="20dp" 
     android:background="#ffffff " 
     android:layout_gravity="center_horizontal" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:id="@+id/editText4" 
     android:layout_margin="20dp" 
     android:background="#ffffff " 
     android:layout_gravity="center_horizontal" /> 

    <EditText 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:id="@+id/editText5" 
     android:layout_margin="20dp" 
     android:background="#ffffff " 
     android:layout_gravity="center_horizontal" /> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:background="#123123 " 
     android:layout_gravity="center_horizontal"> 

     <RadioButton 
      android:layout_width="0dp" 
      android:layout_weight=".5" 
      android:layout_height="wrap_content" 
      android:text="Option 1" 
      android:id="@+id/radioButton" /> 
     <RadioButton 
      android:layout_width="0dp" 
      android:layout_weight=".5" 
      android:layout_height="wrap_content" 
      android:text="Option 2" 
      android:id="@+id/radioButton2" /> 

    </LinearLayout> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_weight="0.1" 
     android:text="New Button" 
     android:id="@+id/button" 
     android:layout_gravity="center_horizontal" /> 


</LinearLayout> 
+0

Großartig, es hat geholfen. – Kobra

+0

aber, wie kann ich das gleiche mit der Schriftgröße machen? – Kobra

+0

Sie werden [this] (https://developer.android.com/reference/android/widget/TextView.html#attr_android:textAppearance) betrachten Ich hatte noch nie ein Problem damit, also habe ich nie wirklich verwendet, aber es sieht richtig aus – CookieMonster

Verwandte Themen