我正在创建一个ExpandableListView,其中的子项目如下图所示

此布局中的标志是动态的,数据仅返回文本和图像路径所需的标志数量(即:参加锦标赛的球队数量)
现在我要做的是,我已经创建了一个具有HorizontalScrollView的布局
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout">
<ImageView
android:layout_width="40dip"
android:layout_height="40dip"
android:id="@+id/tournament_image"
android:layout_marginLeft="5dip"
android:src="@drawable/form_ico2"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ICC World Twenty20 2014"
android:textAllCaps="true"
android:textSize="20sp"
android:paddingLeft="6dip"
android:textColor="@color/subheading"
android:textStyle="bold"
android:id="@+id/tournament_name"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/tournament_image" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CREATE TEAM"
android:background="@color/red"
android:textAllCaps="true"
android:textColor="@color/white"
android:padding="1dip"
android:textSize="12sp"
android:id="@+id/tournament_button"
android:layout_alignParentLeft="true"
android:layout_marginLeft="53dp"
android:layout_below="@+id/relativeLayout" />
<HorizontalScrollView
android:id="@+id/flags_layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dip"
android:layout_below="@+id/tournament_button"
android:layout_alignParentRight="true">
</HorizontalScrollView>
以及使用ImageView和TextView flag_with_text_layout.xml的另一种布局
<ImageView
android:layout_width="30dip"
android:layout_height="20dip"
android:id="@+id/flag"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:src="@drawable/flag_india"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="IND"
android:gravity="center"
android:textSize="10sp"
android:textColor="@color/grey"
android:id="@+id/name"
android:layout_below="@+id/flag"
android:layout_alignRight="@+id/flag"
android:layout_alignParentLeft="true" />
我在运行时膨胀布局,并加载图像和文本(例如,标志和团队名称)这是我用来膨胀布局的方法
for(TeamModel m : tourn.getTeamModels()){
Log.i(MainActivity.TAG,"team name:"+m.getName());
View view = inflater.inflate(R.layout.flag_with_text_layout,null);
ImageView img = (ImageView)view.findViewById(R.id.flag);
TextView text = (TextView)view.findViewById(R.id.name);
loader.DisplayImage(m.getImage(),img);
text.setText(m.getName());
flagsLayout.addView(view);
}现在的问题是,在运行时为旗帜和团队名称膨胀这么多视图是一个非常繁重的过程,我必须在getChildView方法中完成这一过程,因此我的应用程序停止响应并关闭,没有任何异常或对话,因为手机内存不足
我尝试用另一种方法创建视图,并将其放入ArrayList中,只需在getChildView方法中获取布局,而不是在滚动上创建它……
但这仍然是一个非常繁重的过程,do..can any1帮助我,告诉我做这件事的最好方法?
发布于 2014-04-05 18:58:31
检查loader.DisplayImage(m.getImage(),img);行是否正在从UI线程中的服务器获取图像。如果是这种情况,您需要在后台线程中获取图像,同时显示一些虚拟图像,直到图像被获取。你也可以使用UniversalImageLoader来加载图片:
https://stackoverflow.com/questions/22879680
复制相似问题