0
我已經創建了一個可擴展的ListView我的應用程序下面這個教程:如何將不同的圖標添加到可擴展ListView中的子元素?
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
我想爲右對齊每個孩子添加不同的圖標,我該怎麼辦呢?
任何幫助表示讚賞,感謝
我已經創建了一個可擴展的ListView我的應用程序下面這個教程:如何將不同的圖標添加到可擴展ListView中的子元素?
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
我想爲右對齊每個孩子添加不同的圖標,我該怎麼辦呢?
任何幫助表示讚賞,感謝
在list_item.xml
從您發佈只是把所需要的繪製上的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
標記。
嗨,感謝您的迴應,我在哪個文件中放置了這段代碼? – Spartan123
@ Spartan123通過查看你發佈的文章,我會說在你將數據綁定到子視圖的地方。它是'ExpandableListAdapter.java'中的'getChildView'。您爲孩子設置文字的相同位置。 – nikis