我有一个ListView
,其中每个行视图都是从这个xml布局中膨胀的(通过活动布局inflater):
<?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()
更改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 !!!!
...
}
...
}
}
我想也许我的活动上下文在每次屏幕旋转后仍然存在但如果是这种情况那么它是如何发生的,我该如何避免呢?