布局在设计模式下显示正常但在实际设备中不显示

时间:2017-10-29 21:00:52

标签: android android-layout android-appcompat android-constraintlayout

您好我的布局有问题。它在预览模式和Api等级为24的模拟器上正常工作,但是当我在带有api 19的设备上运行它时,它就会分解并且全部搞砸了。甚至我的编辑文本字段也没有响应。在这里,我粘贴我的XML代码,看看你们是否可以帮助我。

编辑:我很抱歉我粘贴了错误的代码(它不完整)。我已编辑,现在它是正确的。还附上了一些关于命名设备外观的图片。 Here is the messed layout And here is the correct one 另一件事是我使用一个嵌套的约束布局。你能做到的吗?

    <?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>

2 个答案:

答案 0 :(得分:0)

您的显示分辨率可能是问题。

答案 1 :(得分:0)

检查build.gradle(模块应用程序)中的minSdkVersion&amp; targetSdkVersion,你的设备可能不在范围内,如果这样正确