什么会导致这个XML耗尽内存

时间:2014-04-11 22:02:32

标签: android xml heap-memory

我有一个scrollveiw根布局包装一个相对布局与一些Imageview,textviews等。 出于某种原因,在访问此XML文件时,它会占用大量的堆空间。已解决所有lint错误,但仍有问题,这里是代码:

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

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_app"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    >

    <RelativeLayout 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:id="@+id/image_wrapper"
      >

        <!-- First Ad -->



        <!-- Top Notes -->

        <TextView
            android:id="@+id/tv_testSelected_TopNotes"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:layout_marginTop="20dp"
            android:text="@string/sample_notes"
            android:textColor="#c4c4c4" />

        <!-- white line splittong widgets -->
        <ImageView
            android:id="@+id/splitter"
            android:contentDescription="@string/splitter"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tv_testSelected_TopNotes"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="20dp"
            android:src="@drawable/splitter" />

        <!-- Section 1 Displine and Test Name and default displine specific image -->

        <TextView
            android:id="@+id/tv_testSelected_Displine"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/tv_testSelected_TopNotes"
            android:layout_below="@+id/splitter"
            android:layout_marginTop="30dp"
            android:text="Haematology"
            android:textColor="#55bbfa"
            android:textSize="20sp" />

        <!-- test name -->

        <TextView
            android:id="@+id/tv_setelectedTest_TestName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/tv_testSelected_Displine"
            android:layout_alignBottom="@+id/tv_testSelected_Displine"
            android:layout_marginLeft="15dp"
            android:layout_toRightOf="@+id/tv_testSelected_Displine"
            android:text="TEST"
            android:textColor="#FFFFFF"
            android:textSize="20sp" />

        <!-- displine specific image1_image -->
        <ImageView
            android:id="@+id/iv_selectedTest_TestImage"
            android:contentDescription="@string/imagedescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tv_testSelected_Displine"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:src="@drawable/image1" />

        <!-- Phone NUmber and Call -->


         <TextView
            android:id="@+id/tv_selectedTest_MainText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/iv_selectedTest_TestImage"
            android:layout_marginTop="20dp"
            android:text="Comments: "
            android:textColor="#c4c4c4" />

         <!-- orginal number text view was here-->
         <TextView
            android:id="@+id/tv_selectedTest_PhoneNumber"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/iv_selectedTest_TestImage"
            android:layout_toRightOf="@+id/tv_selectedTest_MainText"
            android:layout_alignTop="@+id/tv_selectedTest_MainText"

            android:text="Number "
            android:textColor="#55bbfa"
            android:textSize="20sp" />



          <!-- Section 2 contains test tube image and tanle with details-->

    <LinearLayout
         android:id="@+id/tv_selectedTest_Section2"
         android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_below="@+id/tv_selectedTest_PhoneNumber" >




<!--test tube image-->

        <ImageView
            android:id="@+id/image2_selectedTest_Tubes"
            android:contentDescription="@string/imagedescription"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="30dp"
            android:layout_marginRight="30dp"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:src="@drawable/image2" />

        </LinearLayout>
<!--end section 2-->         




         <!-- Table with lots of details -->

         <TableLayout 
             android:id="@+id/testSelcted_tabl"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv_selectedTest_Section2"
        android:layout_marginTop="20dp" 
        android:layout_marginRight="10dp"
        android:layout_marginLeft="5dp"

             >

             <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:weightSum="3" >

            <TextView
                android:id="@+id/tvTable_TAT"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/cell_shaoe"
                android:padding="5dp"
                android:typeface="sans"
                android:text="TAT (hrs)"
                 android:textColor="#FFFFFF"
                android:textAppearance="?android:attr/textAppearanceMedium" >
            </TextView>

            <TextView
                android:id="@+id/tvTable_TATText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:background="@drawable/cell_shaoe"
                android:typeface="sans"
                android:ems="10"
                android:hint="Hours"
                android:padding="5dp"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>


             <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:weightSum="3" >

            <TextView
                android:id="@+id/tvTable_Fixation"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/cell_shaoe"
                android:padding="5dp"
                android:typeface="sans"
                android:text="Fixation"
                android:textColor="#FFFFFF"
                android:textAppearance="?android:attr/textAppearanceMedium" >
            </TextView>

            <TextView
                android:id="@+id/tvTFixation_Input"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:background="@drawable/cell_shaoe"
                android:typeface="sans"
                android:ems="10"
                android:hint="Histology"
                android:padding="5dp"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>
              <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:weightSum="3" >

            <TextView
                android:id="@+id/tvTable_TATUrgent"
                android:layout_width="110dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/cell_shaoe"
                android:padding="5dp"
                android:typeface="sans"
                android:text="Urgent"
                android:textColor="#FFFFFF"
                android:textAppearance="?android:attr/textAppearanceMedium" >
            </TextView>

            <TextView
                android:id="@+id/tvTable_TATUrgetInput"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:background="@drawable/cell_shaoe"
                android:typeface="sans"
                android:ems="10"
                android:hint="Hours        "
                android:padding="5dp"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>


              <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:weightSum="3" >

            <TextView
                android:id="@+id/tvTable_TestCode"
                android:layout_width="110dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/cell_shaoe"
                android:padding="5dp"
                android:typeface="sans"
                android:text="Test Code"
                android:textColor="#FFFFFF"
                android:textAppearance="?android:attr/textAppearanceMedium" >
            </TextView>

            <TextView
                android:id="@+id/tvTable_TestCode_Input"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:background="@drawable/cell_shaoe"
                android:typeface="sans"
                android:ems="10"
                android:hint="Code        "
                android:padding="5dp"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>
               <TableRow
            android:id="@+id/tableRow5"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:weightSum="3" >

            <TextView
                android:id="@+id/tvTable_Refeeral_Center"
                android:layout_width="110dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/cell_shaoe"
                android:padding="5dp"
                android:typeface="sans"
                android:text="Referral Lab"
                android:textColor="#FFFFFF"
                android:textAppearance="?android:attr/textAppearanceMedium" >
            </TextView>

            <TextView
                android:id="@+id/tvTable_Referral_Center_Input"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:layout_weight="2"
                android:background="@drawable/cell_shaoe"
                android:typeface="sans"
                android:ems="10"
                android:hint="Hours        "
                android:padding="5dp"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>

               <TableRow
            android:id="@+id/tableRow6"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:weightSum="3" >

            <TextView
                android:id="@+id/tvTable_RefRanges"
                android:layout_width="110dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/cell_shaoe"
                android:padding="5dp"
                android:typeface="sans"
                android:text="Ref Ranges"
                android:textColor="#FFFFFF"
                android:textAppearance="?android:attr/textAppearanceMedium" >
            </TextView>

            <TextView
                android:id="@+id/tvrefRanges_Input"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:layout_weight="2"
                android:background="@drawable/cell_shaoe"
                android:typeface="sans"
                android:ems="10"
                android:hint="Ref Range"
                android:padding="5dp"
                android:textAppearance="?android:attr/textAppearanceMedium" />
        </TableRow>
         </TableLayout>


         <!-- bottom panel with like button and number to ring and nack button -->

         <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="@dimen/height"
    android:layout_below="@+id/testSelcted_tabl"
    android:layout_marginTop="30dp"
     android:background="@color/dark_purple" >

    <LinearLayout
        android:id="@+id/line"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/divider_size"
        android:layout_alignParentBottom="true"
        android:background="@color/dark_blue" >
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@id/line" >

        <ImageButton
            android:id="@+id/btnImg_Back"
            android:layout_width="@dimen/width"
            android:layout_height="fill_parent"
            android:background="@drawable/ui_button_blue"
            android:src="@drawable/ico_left" />

        <LinearLayout
            android:layout_width="@dimen/divider_size"
            android:layout_height="fill_parent"
            android:background="@color/dark_blue" >
        </LinearLayout>

        <TextView
            android:id="@+id/tv_title"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:tag="bold"
            android:text="@string/txt_some_header"
            android:textColor="@color/white"
            android:textSize="@dimen/tex_size_xxlarge" />

        <LinearLayout
            android:layout_width="@dimen/divider_size"
            android:layout_height="fill_parent"
            android:background="@color/dark_blue" >
        </LinearLayout>

        <ImageButton
            android:id="@+id/btnImg_Like"
            android:layout_width="@dimen/width"
            android:layout_height="fill_parent"
            android:background="@drawable/ui_button_blue"
            android:src="@drawable/ico_like" />
    </LinearLayout>
</RelativeLayout>

         <!-- End bottom of blue tab layout -->








         <!-- End top level relative layout -->
</RelativeLayout>
</ScrollView>

任何意见都表示赞赏。 夏兰

1 个答案:

答案 0 :(得分:1)

你的布局文件似乎很大,以至于它可能只是通过这个事实增加了堆的使用量。但如果我不得不指出罪魁祸首,我会选择你的ImageView。请记住,当您加载此布局文件时,所有ImageView都将呈现,如果您的图像文件未经过优化,则可能会出现递增的堆使用情况。

我建议您阅读此参考页,因为您可以确认或放弃这个想法作为罪魁祸首: