簡體   English   中英

如何在展開式ListView的子元素中添加不同的圖標?

[英]How Can I Add Different Icons to Child Elements in Expandable ListView?

我已按照本教程為我的應用創建了Expandable ListView:

http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/

我想為每個向右對齊的孩子添加不同的圖標,我該怎么做?

任何幫助表示贊賞,謝謝

在您發布的文章的list_item.xml ,只需將所需的drawable放在TextView的右側:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="55dip"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/lblListItem"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="17dip"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:drawableRight[End]="@drawable/my_cool_drawable"
        android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft" />
</LinearLayout>

如果每個項目都應具有不同的可繪制對象,則只需在運行時使用setCompoundDrawable方法對其進行設置:

txtListChild.setCompoundDrawable(null, null, myCoolDrawable, null);

您可能還需要指定drawablePadding 順便說一句,本文示例中的LinearLayout是沒有用的,您可以改用FrameLayout甚至檢查merge標簽。

暫無
暫無

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

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