2017-11-11 6 views
-1

Wie im Titel.
Natürlich weiß ich, dass Bildschirme unterschiedliche Verhältnisse haben, und mein Layout wird nie auf jedem Bildschirm genau gleich aussehen. Ich möchte nur, dass die Layout-Komponenten ungefähr die gleichen Größen und Abstände zueinander haben, relativ zur Bildschirmgröße.
Ich verwende RelativeLayout und dp für Boxen und sp für Texte überall statt px, aber es funktioniert immer noch nicht richtig.

Hier ist, wie es auf einem 7" Bildschirm:
Wie sieht das Layout bei jeder Bildschirmgröße gleich aus?

Und auf 5" sieht Bildschirm:

hier Code, wenn es helfen kann:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.whitecake.wordsknowledgetest.MainActivity"> 

    <TextView 
     android:id="@+id/wordLabel" 
     android:layout_width="wrap_content" 
     android:layout_height="50dp" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentStart="true" 
     android:text="TEST" 
     android:textAlignment="center" 
     android:textAppearance="@style/TextAppearance.AppCompat.Title" 
     android:textSize="30sp" /> 

    <EditText 
     android:id="@+id/wordInput" 
     android:layout_width="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/wordLabel" 
     android:layout_marginTop="26dp" 
     android:ems="10" 
     android:inputType="textPersonName" 
     android:text="TEST" 
     android:textAlignment="center" 
     android:textAppearance="@style/TextAppearance.AppCompat.Title" 
     android:layout_height="50dp" 
     android:textSize="30sp" /> 

    <Button 
     android:id="@+id/checkButton" 
     android:layout_height="100dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/wordInput" 
     android:layout_marginTop="23dp" 
     android:onClick="check" 
     android:text="CHECK!" 
     android:layout_width="180dp" 
     android:textAppearance="@style/TextAppearance.AppCompat.Display1" /> 

    <Button 
     android:id="@+id/invertLangButton" 
     android:layout_alignParentBottom="true" 
     android:onClick="invertLang" 
     android:text="INVERT LANGUAGES" 
     android:layout_height="75dp" 
     android:textAppearance="@style/TextAppearance.AppCompat.Large" 
     android:layout_width="240dp" /> 

    <Button 
     android:id="@+id/switchModeButton" 
     android:layout_height="75dp" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:onClick="switchMode" 
     android:text="SWITCH MODE" 
     android:layout_toEndOf="@+id/nextButton" 
     android:layout_width="250dp" 
     android:textAppearance="@style/TextAppearance.AppCompat.Large" /> 

    <TextView 
     android:layout_width="250dp" 
     android:layout_height="wrap_content" 
     android:id="@+id/resultLabel" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_alignTop="@+id/countLabel" 
     android:layout_toStartOf="@+id/switchModeButton" 
     android:textAppearance="@style/TextAppearance.AppCompat.Display2" /> 

    <TextView 
     android:id="@+id/countLabel" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="" 
     android:textAppearance="@style/TextAppearance.AppCompat.Large" 
     android:layout_below="@+id/showButton" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_toRightOf="@+id/nextButton" 
     android:layout_toEndOf="@+id/nextButton" /> 

    <Button 
     android:id="@+id/nextButton" 
     android:layout_height="100dp" 
     android:onClick="next" 
     android:text="NEXT!" 
     android:layout_width="180dp" 
     android:elevation="0dp" 
     android:layout_alignTop="@+id/checkButton" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="0dp" 
     android:textAppearance="@style/TextAppearance.AppCompat.Display1" /> 

    <Button 
     android:id="@+id/showButton" 
     android:layout_height="100dp" 
     android:onClick="show" 
     android:text="SHOW!" 
     android:layout_width="180dp" 
     android:layout_alignTop="@+id/nextButton" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_marginTop="0dp" 
     android:textAppearance="@style/TextAppearance.AppCompat.Display1" /> 

    <EditText 
     android:layout_width="wrap_content" 
     android:inputType="textPersonName" 
     android:text="words" 
     android:ems="10" 
     android:id="@+id/fileName" 
     android:textAlignment="viewEnd" 
     android:textSize="20dp" 
     android:layout_above="@+id/invertLangButton" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_height="50dp" /> 

    <TextView 
     android:text=".txt" 
     android:layout_width="wrap_content" 
     android:id="@+id/extension" 
     android:textAlignment="gravity" 
     android:textSize="20dp" 
     android:layout_alignTop="@+id/fileName" 
     android:layout_toRightOf="@+id/fileName" 
     android:layout_toEndOf="@+id/fileName" 
     android:layout_marginTop="13dp" 
     android:layout_height="50dp" /> 

    <Button 
     android:text="LOAD" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/switchModeButton" 
     android:layout_toLeftOf="@+id/switchModeButton" 
     android:layout_toStartOf="@+id/switchModeButton" 
     android:onClick="loadFile" 
     android:id="@+id/loadButton" 
     android:layout_alignTop="@+id/fileName" 
     android:textSize="20sp" /> 
</RelativeLayout> 
+0

Ich frage mich, warum Sie RelativeLayout verwenden. Verwenden Sie LinearLayout mit Ausrichtung und Gewicht. – Kuls

+0

Ich möchte nur Hochformat verwenden. Was macht "Gewicht"? Ehrlich gesagt, ich bin neu in Android-Codierung. –

Antwort

-1

Sie Ich muss einen neuen Ordner im Res-Bereich des Projekts

erstellen Unterschiedliche Bildschirmgröße zum Erstellen eines anderen Ordners in
Res ----> und Kopieren und Einfügen Ihrer XML-Datei in diesen neu erstellten Ordnern.

keyword land und port arbeiten automatisch.

Layout-sw320dp Layout-sw320dp-Land ----> Normale Layout-sw320dp-Port

Layout-sw360dp Layout-sw360dp-Land Layout-sw360dp-Port

Layout- sw800dp ----------------- tablet ansicht layout-sw800dp-land layout-sw800dp-port

layout-klein ----------- -kleiner Bildschirm Layout-kleines Land Layout-small-port

Layout-großes -------------------- großer Bildschirm Layout-large-Land Layout-large-Port

Siehe diesen Link http://prntscr.com/h91tpi

Verwandte Themen