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

时间:2016-07-23 18:47:48

标签: android android-layout android-constraintlayout

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

我的旧ui仅使用15 MB的ram而新的ui使用~400MB

有人有想法吗?

老ui

在实际的Android设备上使用~15MB的ram 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" />

新ui

在超过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" />

2 个答案:

答案 0 :(得分:1)

似乎错误就在了     编译&#39; com.android.support.constraint:constraint-layout:1.0.0-alpha4&#39;

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

然后我用

def get_job_links(section_URL):
    soup = make_soup(section_URL)
    internerLink = soup.find_all("a", "internerLink primaerElement")
    job_links = [BASE_URL + link["href"] for link in internerLink]
    return job_links


def get_all_job_links(section_URL):
    all_job_links = []
    for page in range(1, PAGE_COUNT + 1):
        newURL = section_URL[:-1] + str(page)
        all_job_links.extend(get_job_links(newURL))
    return all_job_links


def get_job_details(job_URL):
    soup = make_soup(job_URL)
    details = {'job_URL': job_URL, 'refnr': '', 'firmName': '',
               'fName': '', 'sName': '', 'adressStr': '',
               'adressPlz': '', 'adressOrt': '', 'email': '',
               'jobtype': '', 'gender': '', 'status': ''}

    [details.update({'refnr': refnr.text}) for refnr in soup.findAll(id=re.compile("referenznummer"))]
    [details.update({'firmName': firmName.text}) for firmName in
     soup.findAll(id=re.compile("ruckfragenundbewerbungenan_-2147483648"))]
    [details.update({'fName': fName.text + ' '}) for fName in soup.findAll(id=re.compile("vorname_-2147483648"))]
    [details.update({'sName': sName.text}) for sName in soup.findAll(id=re.compile("nachname_-2147483648"))]
    [details.update({'adressStr': adressStr.text}) for adressStr in
     soup.findAll(id=re.compile("ruckfragenUndBewerbungenAn.wert\['adresse'\]Strasse_-2147483648"))]
    [details.update({'adressPlz': adressPlz.text}) for adressPlz in
     soup.findAll(id=re.compile("ruckfragenUndBewerbungenAn.wert\['adresse'\]Plz_-2147483648"))]
    [details.update({'adressOrt': adressOrt.text}) for adressOrt in
     soup.findAll(id=re.compile("ruckfragenUndBewerbungenAn.wert\['adresse'\]Ort_-2147483648"))]
    [details.update({'email': str(email['href'])[7:]}) for email in
     soup.findAll(id=re.compile("vermittlung.stellenangeboteverwalten.detailszumstellenangebot.email"))]

    jobtype = soup.b
    if jobtype:
        jobtype = soup.b.text
    else:
        jobtype = ''
    if jobtype.find("Anwendungsentwicklung") > -1:
        details.update({'jobtype': u"Fachinformatiker für Anwendungsentwicklung"})
    elif jobtype.find("Systemintegration") > -1:
        details.update({'jobtype': u"Fachinformatiker für Systemintegration"})
    elif jobtype.find("Medieninformatik") > -1:
        details.update({'jobtype': u"Medieninformatiker"})
    elif jobtype.find("Informatikkaufmann") > -1:
        details.update({'jobtype': u"Informatikkaufmann"})
    elif jobtype.find("Systemkaufmann") > -1:
        details.update({'jobtype': u"IT-Systemkaufmann"})
    else:
        details.update({'jobtype': u"Informatiker"})

    soup.find("div", {"class": "ausklappBox"}).decompose()
    genderdiv = str(soup.div)
    gender = ''
    if genderdiv.find("Frau") > -1:
        gender += "Frau "
    if genderdiv.find("Herr") > -1:
        gender += "Herr "
    if len(gender) > 5:
        gender = ''
    details.update({'gender': gender})
    return details


def get_all_job_details(section_URL):
    all_job_details = []
    all_job_links = get_all_job_links(section_URL)
    for i in range(len(all_job_links)):
        all_job_details.append(get_job_details(all_job_links[i]))
        printProgress(i, len(all_job_links) - 1, prefix='Progress:', suffix='Complete', barLength=50)
    return all_job_details

def printProgress(iteration, total, prefix='', suffix='', decimals=2, barLength=100):
"""
Call in a loop to create terminal progress bar
@params] =
    iteration   - Required  : current iteration (Int)
    total       - Required  : total iterations (Int)
    prefix      - Optional  : prefix string (Str)
    suffix      - Optional  : suffix string (Str)
    decimals    - Optional  : number of decimals in percent complete (Int)
    barLength   - Optional  : character length of bar (Int)
"""
filledLength = int(round(barLength * iteration / float(total)))
percents = round(100.00 * (iteration / float(total)), decimals)
bar = '#' * filledLength + '-' * (barLength - filledLength)
Sys.stdout.write('%s [%s] %s%s %s\r' % (prefix, bar, percents, '%', suffix)),
Sys.stdout.flush()
if iteration == total:
    print("\n\n")

用新的ui。 现在这个bug已经修复了alpha7

答案 1 :(得分:0)

alpha 4中有一个错误已经在alpha 6中得到解决,这可能会解释你所看到的内容(这显然是完全异常的,Constraint Layout实际上应该使用非常少的内存)。你能检查一下是否修复了你的问题,如果没有提交错误?谢谢!