-2

Hallo Ich habe ein Problem mit meinem Layout. Es funktioniert einwandfrei im Vorschaumodus und auf einem Emulator mit Api-Level 24, aber wenn ich es auf einem Gerät mit api 19 starte, bricht es einfach zusammen und alles wird durcheinander gebracht. Sogar meine Textfelder bearbeiten nicht mehr. Hier füge ich meinen XML-Code ein, um zu sehen, ob ihr mir helfen könnt.Layout zeigt gut im Design-Modus, aber nicht in realen Gerät

EDIT: Es tut mir leid, dass ich den falschen Code eingefügt habe (es war unvollständig). Ich habe bearbeitet und jetzt ist es richtig. Anbei ein paar Bilder davon wie das in den genannten Geräten aussieht. Here is the messed layoutAnd here is the correct one . Eine andere Sache ist, dass ich ein verschachteltes Constraint-Layout verwende. Machst du das, könnte es sein?

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/root" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:focusableInTouchMode="true" 
    tools:context="com.cuantomefalta.cuantomefalta.MainActivity"> 

    <EditText 
     android:id="@+id/weighing3" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_vertical" 
     android:background="@drawable/little_square" 
     android:cursorVisible="false" 
     android:fontFamily="sans-serif-medium" 
     android:gravity="center" 
     android:hint="@string/cero_percent" 
     android:imeOptions="actionDone" 
     android:inputType="number" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" 
     android:visibility="gone" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/weighing2" 
     tools:text="25%" 
     android:layout_marginLeft="8dp" 
     android:layout_marginTop="2dp" 
     android:layout_marginStart="8dp"/> 

    <EditText 
     android:id="@+id/grade3" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_vertical" 
     android:background="@drawable/little_square" 
     android:cursorVisible="false" 
     android:fontFamily="sans-serif-medium" 
     android:gravity="center" 
     android:hint="@string/one" 
     android:imeOptions="actionDone" 
     android:inputType="number" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" 
     android:visibility="gone" 
     app:layout_constraintLeft_toRightOf="@+id/weighing3" 
     app:layout_constraintRight_toLeftOf="@+id/converted3" 
     app:layout_constraintTop_toTopOf="@+id/weighing3" 
     tools:text="100" /> 

    <TextView 
     android:id="@+id/converted3" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_vertical" 
     android:background="@drawable/little_square" 
     android:fontFamily="sans-serif-medium" 
     android:gravity="center" 
     android:text="@string/one_point_cero" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" 
     android:visibility="gone" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="@+id/weighing3" 
     tools:text="8.5" 
     android:layout_marginTop="2dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginEnd="8dp"/> 

    <EditText 
     android:id="@+id/weighing2" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_vertical" 
     android:background="@drawable/little_square" 
     android:cursorVisible="false" 
     android:fontFamily="sans-serif-medium" 
     android:gravity="center" 
     android:hint="@string/cero_percent" 
     android:imeOptions="actionDone" 
     android:inputType="number" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" 
     android:visibility="gone" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/weighing1" 
     tools:text="25%" 
     android:layout_marginLeft="8dp" 
     android:layout_marginTop="2dp" 
     android:layout_marginStart="8dp"/> 

    <EditText 
     android:id="@+id/grade2" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_vertical" 
     android:background="@drawable/little_square" 
     android:cursorVisible="false" 
     android:fontFamily="sans-serif-medium" 
     android:gravity="center" 
     android:hint="@string/one" 
     android:imeOptions="actionDone" 
     android:inputType="number" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" 
     android:visibility="gone" 
     app:layout_constraintLeft_toRightOf="@+id/weighing2" 
     app:layout_constraintRight_toLeftOf="@+id/converted2" 
     app:layout_constraintTop_toTopOf="@+id/weighing2" 
     tools:text="100" /> 

    <TextView 
     android:id="@+id/converted2" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_vertical" 
     android:background="@drawable/little_square" 
     android:fontFamily="sans-serif-medium" 
     android:gravity="center" 
     android:text="@string/one_point_cero" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" 
     android:visibility="gone" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="@+id/weighing2" 
     tools:text="8.5" 
     android:layout_marginTop="0dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginEnd="8dp"/> 

    <EditText 
     android:id="@+id/weighing1" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_vertical" 
     android:background="@drawable/little_square" 
     android:cursorVisible="false" 
     android:fontFamily="sans-serif-medium" 
     android:gravity="center" 
     android:hint="@string/cero_percent" 
     android:imeOptions="actionDone" 
     android:inputType="number" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" 
     android:visibility="gone" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/weighing" 
     tools:text="25%" 
     android:layout_marginLeft="8dp" 
     android:layout_marginTop="2dp" 
     android:layout_marginStart="8dp"/> 

    <EditText 
     android:id="@+id/grade1" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_vertical" 
     android:background="@drawable/little_square" 
     android:cursorVisible="false" 
     android:fontFamily="sans-serif-medium" 
     android:gravity="center" 
     android:hint="@string/one" 
     android:imeOptions="actionDone" 
     android:inputType="number" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" 
     android:visibility="gone" 
     app:layout_constraintLeft_toRightOf="@+id/weighing1" 
     app:layout_constraintRight_toLeftOf="@+id/converted1" 
     app:layout_constraintTop_toTopOf="@+id/weighing1" 
     tools:text="100" 
     android:layout_marginTop="0dp" 
     app:layout_constraintHorizontal_bias="0.5" /> 

    <TextView 
     android:id="@+id/converted1" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_vertical" 
     android:background="@drawable/little_square" 
     android:fontFamily="sans-serif-medium" 
     android:gravity="center" 
     android:text="@string/one_point_cero" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" 
     android:visibility="gone" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="@+id/weighing1" 
     tools:text="8.5" 
     android:layout_marginTop="0dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginEnd="8dp"/> 

    <EditText 
     android:id="@+id/weighing" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_vertical" 
     android:layout_marginLeft="8dp" 
     android:layout_marginStart="8dp" 
     android:layout_marginTop="2dp" 
     android:background="@drawable/little_square" 
     android:cursorVisible="false" 
     android:fontFamily="sans-serif-medium" 
     android:gravity="center" 
     android:hint="@string/cero_percent" 
     android:imeOptions="actionDone" 
     android:inputType="number" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     tools:text="25%" 

     /> 

    <EditText 
     android:id="@+id/grade" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_vertical" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="8dp" 
     android:background="@drawable/little_square" 
     android:cursorVisible="false" 
     android:fontFamily="sans-serif-medium" 
     android:gravity="center" 
     android:hint="@string/one" 
     android:imeOptions="actionDone" 
     android:inputType="number" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" 
     app:layout_constraintLeft_toRightOf="@+id/weighing" 
     app:layout_constraintRight_toLeftOf="@+id/converted" 
     app:layout_constraintTop_toTopOf="@+id/weighing" 
     tools:text="100" /> 

    <TextView 
     android:id="@+id/converted" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_vertical" 
     android:layout_marginEnd="8dp" 
     android:layout_marginRight="8dp" 
     android:background="@drawable/little_square" 
     android:fontFamily="sans-serif-medium" 
     android:gravity="center" 
     android:text="@string/one_point_cero" 
     android:textColor="@android:color/white" 
     android:textSize="25sp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="@+id/weighing" 
     tools:text="1.0" /> 

    <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     ads:adSize="SMART_BANNER" 
     ads:adUnitId="ca-app-pub-2505831397151341/8310107897" 
     ads:layout_constraintBottom_toBottomOf="parent" 
     ads:layout_constraintHorizontal_bias="0.0" 
     ads:layout_constraintLeft_toLeftOf="parent" 
     ads:layout_constraintRight_toRightOf="parent" /> 

    <android.support.constraint.ConstraintLayout 
     android:id="@+id/shareView" 
     android:layout_width="250dp" 
     android:layout_height="250dp" 
     android:layout_gravity="center_vertical" 
     android:background="@drawable/big_circle" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="8dp" 
     app:layout_constraintBottom_toTopOf="@+id/adView" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent"> 


     <TextSwitcher 
      android:id="@+id/final_grade" 
      android:layout_width="0dp" 
      android:layout_height="234dp" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent"> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center_vertical" 
       android:layout_marginTop="-12dp" 
       android:fontFamily="sans-serif-medium" 
       android:gravity="center" 
       android:textColor="@android:color/white" 
       android:textSize="125sp" 
       tools:text="55" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center_vertical" 
       android:layout_marginTop="-12dp" 
       android:fontFamily="sans-serif-medium" 
       android:gravity="center" 
       android:textColor="@android:color/white" 
       android:textSize="125sp" 
       tools:text="99" /> 
     </TextSwitcher> 

     <EditText 
      android:id="@+id/goalGrade" 
      android:layout_width="60dp" 
      android:layout_height="60dp" 
      android:layout_gravity="center_vertical" 
      android:background="@drawable/little_circle" 
      android:cursorVisible="false" 
      android:fontFamily="sans-serif-medium" 
      android:gravity="center" 
      android:inputType="number" 
      android:imeOptions="actionDone" 
      android:text="@string/five" 
      android:textColor="@android:color/white" 
      android:textSize="30sp" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintBottom_toBottomOf="parent" 
      tools:text="@string/five" 
      android:layout_marginBottom="8dp" /> 

     <TextView 
      android:id="@+id/first_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:fontFamily="sans-serif-medium" 
      android:text="@string/me_faltan" 
      android:textColor="@android:color/white" 
      android:textSize="25sp" 
      android:visibility="gone" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" 
      app:layout_constraintTop_toTopOf="@+id/shareView" 
      android:layout_marginTop="24dp" 
      /> 

     <TextView 
      android:id="@+id/second_text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:fontFamily="sans-serif-medium" 
      android:text="@string/para_llegar" 
      android:textColor="@android:color/white" 
      android:textSize="20sp" 
      android:visibility="gone" 
      app:layout_constraintBottom_toTopOf="@+id/goalGrade" 
      app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintRight_toRightOf="parent" /> 
    </android.support.constraint.ConstraintLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/floatingActionButton8" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="16dp" 
     android:clickable="true" 
     app:fabSize="mini" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="@+id/shareView" 
     app:srcCompat="@drawable/ic_add_white_24dp" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/floatingActionButton9" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="16dp" 
     android:clickable="true" 
     app:fabSize="mini" 
     app:layout_constraintLeft_toLeftOf="@+id/floatingActionButton8" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/floatingActionButton8" 
     app:srcCompat="@drawable/ic_clear_white_24dp" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/floatingActionButton10" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="16dp" 
     android:clickable="true" 
     app:fabSize="mini" 
     app:layout_constraintLeft_toLeftOf="@+id/floatingActionButton9" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/floatingActionButton9" 
     app:srcCompat="@drawable/ic_delete_sweep_white_24dp" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/floatingActionButton11" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginTop="16dp" 
     android:clickable="true" 
     app:fabSize="mini" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="@+id/floatingActionButton10" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/floatingActionButton10" 
     app:layout_constraintBottom_toBottomOf="@id/shareView" 
     app:srcCompat="@drawable/ic_play_arrow_white_24dp" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/floatingActionButton12" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="16dp" 
     android:layout_marginRight="0dp" 
     android:clickable="true" 
     app:fabSize="mini" 
     app:layout_constraintRight_toRightOf="@id/shareView" 
     app:layout_constraintBottom_toBottomOf="@+id/shareView" 
     app:srcCompat="@drawable/ic_share_white_24dp" 
     android:visibility="gone" 
     android:layout_marginBottom="56dp" /> 

</android.support.constraint.ConstraintLayout> 
+0

Können Sie Screenshots von Post, wie es aussehen sollte vs. wie es aussieht, ? – damian

+0

Stellen Sie sicher, dass alle Ansichten, die direkte untergeordnete Elemente des ConstraintLayouts sind, horizontal und vertikal eingeschränkt sind. Ich kann Ihnen sagen, dass Ihr 'TextSwitcher' nicht vertikal eingeschränkt ist. Ich würde auch die oberste Beschränkung für den "TextView" "first_text" in "parent" anstatt die ID des "ConstraintLayout" ändern. Probieren Sie diese Dinge aus, um zu sehen, ob Ihre Probleme gelöst werden. (Sie sind gute Dinge zu tun, egal.) – Cheticamp

+0

Hallo Ich habe die Screenshots @damian gepostet Wie Sie angefordert –

Antwort

0

Möglicherweise ist die Bildschirmauflösung das Problem.

+0

Hallo @Ognjen Stanojevic Warum sollte dies ein Problem sein, wenn alle meine Einheiten in DP sind? sind das nicht unabhängig von der Dichte der Bildschirme? –

0

Prüfung im build.gradle (Modul App) für das minSdkVersion & targetSdkVersion, kann das Gerät nicht im Bereich, wenn dem so ist richtig, dass

+0

Hallo @LaideLawal das ist nicht das Problem mein min SDK ist 16 und mein Ziel ist 26, so sollte es in Ordnung sein, auf api 19 Geräte laufen –

Verwandte Themen