2011-05-19 162 views

回答

0

您是否將背景可繪製設置爲圖標的正確高度?如果它使用默認的背景可繪製,即使您的可繪圖較小,也會得到默認圖標的高度/寬度。

10

這將肯定工作:

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_empty="true"> 
    <layer-list> 
     <item 
      android:left="0dp" 
      android:right="3dp" 
      android:top="20dp" 
      android:bottom="20dp" 
      android:drawable="@drawable/down_indication"> 
     </item> 
    </layer-list> 
    </item> 

    <item android:state_expanded="true"> 
    <layer-list> 
     <item 
      android:left="0dp" 
      android:right="3dp" 
      android:top="20dp" 
      android:bottom="20dp" 
      android:drawable="@drawable/up_indication"> 
     </item> 
    </layer-list> 
    </item> 

</selector> 
+1

及其me..thanks工作@ Satheesh..its真的rooking碼(Y) – 2015-01-30 10:42:58

+0

沒有。不起作用。它缺少一個。 :-( – 2017-03-24 00:35:33

+0

崩潰:java.lang.IllegalArgumentException:在android.graphics中,寬度和高度必須> 0 。Bitmap.createBitmap(Bitmap.java:81 – matheszabi 2018-01-26 10:16:36

6

無論你設置你的指標爲,的尺寸是什麼ListView控件佈局的分組指示容器具有高度match_parent,因此你的指標會總是被拉長。

我用得到這個工作:

(1)設置組指標爲null

(2)包括集團佈局在我的自定義組指示燈。

(3)有一個groupClickListener改變你的狀態指標。

代碼片斷:

(1)mListView.setGroupIndicator(null);

(2)包括我的在組佈局指示符。

<ImageView 
    android:id="@+id/help_group_indicator" 
    android:layout_width="@dimen/help_group_indicator_dimension" 
    android:layout_height="@dimen/help_group_indicator_dimension" 
    android:layout_marginTop="@dimen/help_group_indicator_dimension" 
    android:src="@drawable/down_icon" /> 

(3)

mListView.setOnGroupClickListener(new OnGroupClickListener() { 
     @Override 
     public boolean onGroupClick(ExpandableListView parent, View clickedView, int groupPosition, long rowId) { 
      ImageView groupIndicator = (ImageView) clickedView.findViewById(R.id.help_group_indicator); 
      if (parent.isGroupExpanded(groupPosition)) { 
       parent.collapseGroup(groupPosition); 
       groupIndicator.setImageResource(R.drawable.down_icon); 
      } else { 
       parent.expandGroup(groupPosition); 
       groupIndicator.setImageResource(R.drawable.up_icon); 
      } 
      return true; 
     } 
    }); 

通過@Satheesh建議將工作答案,但只有當所有groupViews具有相同的高度。如果您的組佈局有說,包裝文字和wrap_content高度,高度可能會根據您的內容而有所不同,並且您設置的填充可能不再有效。

+0

當組項目的大小不是固定時,面對相同的場景並且它對我有幫助,這很有效。謝謝。 – flexdroid 2015-02-24 20:10:53

0

如果你有TextView的旁邊組佈局的指示圖標,你也可以做到以下幾點:

(1)在ExpandableListView XML佈局,刪除groupIndicator:

android:groupIndicator="@null" 

(2)在您的自定義ExpandableListAdapter,設置左繪製的TextView中的getGroupView(...)方法:

int leftIcon=R.drawable.ic_noexpand; 
if (isExpanded) leftIcon=R.drawable.ic_expand; 
lblListHeader.setCompoundDrawablesWithIntrinsicBounds(
    ContextCompat.getDrawable(_context,leftIcon),null,null,null); 

(當Min API爲> = 21,你可以使用語境,而不是ContextCompat)

(3)設置在android:paddingLeft="0dp" XML組佈局,因爲該指示圖標空間現在是空的

相關問題