首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >具有动态布局的ListView项目(Imageview,TextView)

具有动态布局的ListView项目(Imageview,TextView)
EN

Stack Overflow用户
提问于 2014-04-05 18:31:39
回答 1查看 353关注 0票数 1

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

此布局中的标志是动态的,数据仅返回文本和图像路径所需的标志数量(即:参加锦标赛的球队数量)

现在我要做的是,我已经创建了一个具有HorizontalScrollView的布局

代码语言:javascript
运行
复制
<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的另一种布局

代码语言:javascript
运行
复制
<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" />

我在运行时膨胀布局,并加载图像和文本(例如,标志和团队名称)这是我用来膨胀布局的方法

代码语言:javascript
运行
复制
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帮助我,告诉我做这件事的最好方法?

EN

回答 1

Stack Overflow用户

发布于 2014-04-05 18:58:31

检查loader.DisplayImage(m.getImage(),img);行是否正在从UI线程中的服务器获取图像。如果是这种情况,您需要在后台线程中获取图像,同时显示一些虚拟图像,直到图像被获取。你也可以使用UniversalImageLoader来加载图片:

https://github.com/nostra13/Android-Universal-Image-Loader

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22879680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档