gpt4 book ai didi

Android Constraintlayout 使用太多内存 (ram)(内存泄漏)

转载 作者:行者123 更新时间:2023-11-30 01:09:38 29 4
gpt4 key购买 nike

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

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

有人有想法吗?

旧用户界面

在实际的 Android 设备上使用约 15MB 的内存 enter image description here

enter image description here

<?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!!! enter image description here

enter image description here

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

最佳答案

看来bug在 编译 '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'

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

关于Android Constraintlayout 使用太多内存 (ram)(内存泄漏),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38545319/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com