簡體   English   中英

具有動態布局的ListView項(Imageview,TextView)

[英]ListView item with dynamic layout(Imageview, TextView)

即時通訊創建一個ExpandableListView,其中子項看起來像下面的圖像 在此處輸入圖片說明

此布局中的標志是動態的,數據僅返回文本和圖像路徑所需的標志數(即:參加錦標賽的團隊數)

現在我正在做的是我創建了一個帶有Horizo​​ntalScrollView的布局

<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方法中獲取布局,而不是在滾動時創建它...

但是這樣做仍然是一個非常繁重的過程。任何人都能幫助我並告訴我這樣做的最佳方法嗎?

檢查loader.DisplayImage(m.getImage(),img); 行正在從UI線程中的服務器獲取圖像。 如果是這種情況,則需要在后台線程中獲取圖像,同時顯示一些虛擬圖像,直到獲取圖像為止。 您也可以使用UniversalImageLoader加載圖像:-

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM