1

我真的不明白约束布局会发生什么。

我的旧 ui 仅使用 15 MB 内存,而新 ui 使用 ~400MB

有人有想法吗?

老用户界面

在实际的 Android 设备上使用约 15MB 的内存 在此处输入图像描述

在此处输入图像描述

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text=" 11 January 2016"
    android:id="@+id/dateTv"
    android:gravity="center_horizontal"
    app:layout_constraintLeft_toLeftOf="@+id/constraintLayout4"
    android:layout_marginStart="16dp"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintTop_toTopOf="@+id/constraintLayout4"
    android:layout_marginTop="16dp" />


<TextView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="12 : 59 PM"
    android:id="@+id/timeTv"
    android:gravity="center_horizontal"
    app:layout_constraintLeft_toRightOf="@+id/dateTv"
    app:layout_constraintTop_toTopOf="@+id/dateTv"
    app:layout_constraintRight_toRightOf="@+id/constraintLayout4"
    android:layout_marginEnd="16dp"
    app:layout_constraintHorizontal_bias="1.0" />

<SeekBar
    android:layout_width="0dp"
    android:layout_height="20dp"
    android:id="@+id/seekBarFoodQuantity"
    android:max="10"
    app:layout_constraintLeft_toRightOf="@+id/decrease"
    android:layout_marginStart="8dp"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintTop_toBottomOf="@+id/timeTv"
    android:layout_marginTop="48dp"
    app:layout_constraintRight_toLeftOf="@+id/increase"
    android:layout_marginEnd="8dp"
    tools:layout_constraintRight_creator="1" />

<TextView
    android:text="-"
    android:gravity="center"
    android:layout_width="49dp"
    android:layout_height="49dp"
    android:id="@+id/decrease"
    android:textSize="40sp"
    android:background="@color/red_300"
    app:layout_constraintLeft_toLeftOf="@+id/constraintLayout4"
    android:layout_marginStart="8dp"
    app:layout_constraintTop_toTopOf="@+id/seekBarFoodQuantity"
    app:layout_constraintBottom_toBottomOf="@+id/seekBarFoodQuantity" />

<TextView
    android:text="+"
    android:layout_width="49dp"
    android:layout_height="49dp"
    android:id="@+id/increase"
    android:textSize="40sp"
    android:background="@color/green_400"
    android:gravity="center"
    app:layout_constraintTop_toTopOf="@+id/seekBarFoodQuantity"
    app:layout_constraintRight_toRightOf="@+id/constraintLayout4"
    android:layout_marginEnd="8dp"
    app:layout_constraintBottom_toBottomOf="@+id/seekBarFoodQuantity" />

<TextView
    android:text="@string/quantity"
    android:layout_width="137dp"
    android:layout_height="49dp"
    android:id="@+id/tvQuantity"
    android:textSize="20sp"
    android:gravity="center"
    app:layout_constraintLeft_toLeftOf="@+id/constraintLayout4"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintTop_toBottomOf="@+id/seekBarFoodQuantity"
    app:layout_constraintRight_toRightOf="@+id/constraintLayout4"
    tools:layout_constraintRight_creator="1"
    app:layout_constraintBottom_toBottomOf="@+id/constraintLayout4"
    android:layout_marginBottom="16dp"
    app:layout_constraintVertical_bias="0.0" />

<TextView
    android:text="Save"
    android:layout_width="137dp"
    android:layout_height="49dp"
    android:id="@+id/tvSave"
    android:textSize="20sp"
    android:gravity="center"
    app:layout_constraintLeft_toLeftOf="@+id/constraintLayout4"
    tools:layout_constraintLeft_creator="1"
    app:layout_constraintTop_toBottomOf="@+id/seekBarFoodQuantity"
    app:layout_constraintRight_toRightOf="@+id/constraintLayout4"
    tools:layout_constraintRight_creator="1"
    app:layout_constraintBottom_toBottomOf="@+id/constraintLayout4"
    android:layout_marginBottom="16dp" />

<include layout="@layout/bottom_bar" android:id="@+id/bottombarAddFood"
    android:layout_width="0dp"
    android:layout_height="72dp"
    app:layout_constraintRight_toRightOf="@+id/constraintLayout4"
    app:layout_constraintBottom_toBottomOf="@+id/constraintLayout4" />

新用户界面

在超过 400 MB 的实际 Android 设备上使用 ram!!! 在此处输入图像描述

在此处输入图像描述

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text=" 11 January 2016"
    android:id="@+id/dateTv"
    android:gravity="center_horizontal"
    app:layout_constraintLeft_toLeftOf="@+id/constraintLayout4"
    android:layout_marginStart="16dp"
    app:layout_constraintTop_toBottomOf="@+id/editText2"
    android:layout_marginTop="8dp" />


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="12 : 59 PM"
    android:id="@+id/timeTv"
    android:gravity="center_horizontal"
    app:layout_constraintTop_toTopOf="@+id/dateTv"
    app:layout_constraintRight_toRightOf="@+id/constraintLayout4"
    android:layout_marginEnd="16dp"
    app:layout_constraintBottom_toBottomOf="@+id/dateTv" />

<SeekBar
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:id="@+id/seekBarFoodQuantity"
    android:max="10"
    app:layout_constraintLeft_toRightOf="@+id/decrease"
    android:layout_marginStart="8dp"
    app:layout_constraintTop_toTopOf="@+id/decrease"
    app:layout_constraintRight_toLeftOf="@+id/increase"
    android:layout_marginEnd="8dp"
    app:layout_constraintBottom_toBottomOf="@+id/decrease" />

<TextView
    android:text="-"
    android:gravity="center"
    android:layout_width="49dp"
    android:layout_height="49dp"
    android:id="@+id/decrease"
    android:textSize="40sp"
    android:background="@color/red_300"
    app:layout_constraintLeft_toLeftOf="@+id/constraintLayout4"
    android:layout_marginStart="16dp"
    app:layout_constraintTop_toBottomOf="@+id/textView2"
    android:layout_marginTop="24dp" />

<TextView
    android:text="+"
    android:layout_width="49dp"
    android:layout_height="49dp"
    android:id="@+id/increase"
    android:textSize="40sp"
    android:background="@color/green_400"
    android:gravity="center"
    app:layout_constraintTop_toTopOf="@+id/seekBarFoodQuantity"
    app:layout_constraintRight_toRightOf="@+id/constraintLayout4"
    android:layout_marginEnd="16dp"
    app:layout_constraintBottom_toBottomOf="@+id/seekBarFoodQuantity" />

<TextView
    android:text="@string/quantity"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tvQuantity"
    android:textSize="20sp"
    android:gravity="center"
    app:layout_constraintLeft_toLeftOf="@+id/seekBarFoodQuantity"
    app:layout_constraintTop_toBottomOf="@+id/seekBarFoodQuantity"
    android:layout_marginTop="8dp"
    app:layout_constraintRight_toRightOf="@+id/seekBarFoodQuantity" />

<TextView
    android:text="Save"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/tvSave"
    android:textSize="20sp"
    android:gravity="center"
    app:layout_constraintLeft_toLeftOf="@+id/constraintLayout4"
    android:layout_marginStart="16dp"
    app:layout_constraintRight_toRightOf="@+id/constraintLayout4"
    android:layout_marginEnd="16dp"
    app:layout_constraintBottom_toTopOf="@+id/bottombarAddFood"
    android:layout_marginBottom="8dp" />

<include layout="@layout/bottom_bar" android:id="@+id/bottombarAddFood"
    android:layout_width="wrap_content"
    android:layout_height="72dp"
    app:layout_constraintLeft_toLeftOf="@+id/constraintLayout4"
    app:layout_constraintRight_toRightOf="@+id/constraintLayout4"
    app:layout_constraintBottom_toBottomOf="@+id/constraintLayout4" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:text="Name"
    android:ems="10"
    android:id="@+id/editText2"
    app:layout_constraintLeft_toLeftOf="@+id/constraintLayout4"
    android:layout_marginStart="16dp"
    app:layout_constraintTop_toTopOf="@+id/constraintLayout4"
    android:layout_marginTop="16dp"
    app:layout_constraintRight_toRightOf="@+id/constraintLayout4"
    android:layout_marginEnd="16dp" />

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/radioLittle"
    app:layout_constraintLeft_toLeftOf="@+id/constraintLayout4"
    android:layout_marginStart="16dp"
    app:layout_constraintTop_toBottomOf="@+id/dateTv"
    android:layout_marginTop="32dp"
    app:layout_constraintRight_toLeftOf="@+id/radioMedium"
    android:layout_marginEnd="8dp"
    app:layout_constraintHorizontal_bias="0.33" />

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/radioMedium"
    app:layout_constraintLeft_toLeftOf="@+id/constraintLayout4"
    android:layout_marginStart="16dp"
    app:layout_constraintTop_toTopOf="@+id/radioMost"
    app:layout_constraintRight_toRightOf="@+id/constraintLayout4"
    android:layout_marginEnd="16dp"
    app:layout_constraintBottom_toBottomOf="@+id/radioMost"
    app:layout_constraintHorizontal_bias="0.75"
    app:layout_constraintVertical_bias="1.0" />

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/radioMost"
    app:layout_constraintLeft_toRightOf="@+id/radioLittle"
    android:layout_marginStart="8dp"
    app:layout_constraintTop_toTopOf="@+id/radioLittle"
    app:layout_constraintRight_toLeftOf="@+id/radioMedium"
    android:layout_marginEnd="8dp"
    app:layout_constraintBottom_toBottomOf="@+id/radioLittle" />

<TextView
    android:text="Little"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView2"
    app:layout_constraintLeft_toLeftOf="@+id/radioLittle"
    app:layout_constraintTop_toBottomOf="@+id/radioLittle"
    android:layout_marginTop="8dp"
    app:layout_constraintRight_toRightOf="@+id/radioLittle" />

<TextView
    android:text="Medium"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView3"
    app:layout_constraintLeft_toLeftOf="@+id/radioMost"
    app:layout_constraintTop_toBottomOf="@+id/radioMost"
    android:layout_marginTop="8dp"
    app:layout_constraintRight_toRightOf="@+id/radioMost" />

<TextView
    android:text="Most"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView4"
    app:layout_constraintLeft_toLeftOf="@+id/radioMedium"
    app:layout_constraintTop_toBottomOf="@+id/radioMedium"
    android:layout_marginTop="8dp"
    app:layout_constraintRight_toRightOf="@+id/radioMedium" />

4

2 回答 2

1

似乎该错误在编译'com.android.support.constraint:constraint-layout:1.0.0-alpha4'

新的 ui 使用 alpha4 但旧的 ui 使用 alpha3

然后我用

compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha3'

使用新的用户界面。 现在这个错误也已经在 alpha7 上修复了

于 2016-07-23T18:57:32.560 回答
0

alpha 4 中有一个 bug 已在 alpha 6 中得到解决,这可以解释您所看到的(这显然是完全不正常的,约束布局实际上应该使用很少的 ram)。你能检查一下这是否解决了你的问题,如果没有提交错误?谢谢!

于 2016-08-10T15:57:50.960 回答