1

我有一个ListView每个行视图都从这个 xml 布局(通过活动布局充气器)膨胀的地方:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:baselineAligned="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/topic_list_item_selector"
android:orientation="horizontal"
android:paddingLeft="@dimen/list_item_padding_horizontal_big"
android:paddingBottom="@dimen/list_item_padding_vertical_big"
android:paddingTop="@dimen/list_item_padding_vertical_big" >

<LinearLayout
    android:id="@+id/topics_list_edit_row_label_color"
    android:layout_width="@dimen/label_rect_edge_size"
    android:layout_height="@dimen/label_rect_edge_size"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/topics_list_edit_row_label_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="#ffffff"
        android:textSize="@dimen/label_text_size" />
</LinearLayout>

<LinearLayout
    android:id="@+id/topics_list_edit_row_text"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:layout_weight="1"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/topics_list_edit_row_text_title"
        style="@style/DefaultText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="title" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/topics_list_edit_row_text_detail_section"
            style="@style/DetailText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="2 sections"
            android:textColor="#818181" />

        <TextView
            android:id="@+id/topics_list_edit_row_text_detail_point"
            style="@style/DetailText"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="85 points"
            android:textColor="#818181" />
    </LinearLayout>
</LinearLayout>

</LinearLayout>

当我通过在我的适配器中返回此视图时getView(),一切正常。

TextView但是当我通过setText()in更改一些文本时getView(),我的应用程序在每次屏幕旋转时会多消耗大约 1mb:

public class TopicListAdapter extends BaseAdapter{
...
public View getView(int position, View convertView, ViewGroup parent)  {
     View rowView;

 if (convertView == null)
     {
     LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
         rowView = inflater.inflate(R.layout.topics_list_edit_row, parent, false);  
         ...

         Typeface myTypeface = Typeface.createFromAsset(context.getAssets(), "Roboto-Thin.ttf");     //Added

         TextView labelT = (TextView) rowView.findViewById(R.id.topics_list_edit_row_label_text);
     labelT.setTypeface(myTypeface);   //Added
         labelT.setText("A"); //!!!! when I delete this line everything works normally !!!!
         ...
      }
      ...
 }
 }

我想也许我的活动上下文在每次屏幕旋转后仍然存在,但如果是这种情况,那么它是如何发生的,我该如何避免它?

4

0 回答 0