2013-04-24 109 views
5

我一直在使用與組指標一個可擴展的列表視圖顯示列表的右側,在此我已經標題名稱是單行我的輸出這樣的可擴展列表視圖指標顯示標題高度?

enter image description here

在上圖中我的指標是好看。 下面的圖片在我的指示找不好就擴大了,爲什麼出現這種情況

enter image description here

這裏是我的代碼

mExpandableList = (ExpandableListView)findViewById(R.id.expandable_list); 
    mExpandableList.setIndicatorBounds(width - GetPixelFromDips(40), width - GetPixelFromDips(10)); 

XML是

 <ExpandableListView 
    android:id="@+id/expandable_list"   
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:groupIndicator="@drawable/group_indicator" /> 

group_indicator.xml被

<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item 
     android:drawable="@drawable/arrow_down"  android:state_expanded="true"/> 
    <item android:drawable="@drawable/arrow_up"/> 
</selector> 

任何一個有想法的幫助,當你誇大它放在你的adapterClass的getGroupView()這一........

+0

您使用哪個佈局來設置組項目? – AlexBcn 2013-04-24 12:28:27

+0

@AlexBcn linearlayout ......... – NagarjunaReddy 2013-04-24 12:34:07

回答

0

看看你正在使用您的custom_group_layout.xml的看法。您的指標的視圖可能具有fill_parent,這就是爲什麼當您的組包含更多文本行時,您的項目正在伸展他的圖標。

An example

2

我解決這個問題更復雜的方式,但它的工作原理:

片段與擴展列表佈局文件:

<ExpandableListView 
    android:id="@+id/accordion" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:groupIndicator="@android:color/transparent" 
    android:scrollbars="none" > 
</ExpandableListView> 

佈局列表組元素

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/accordion_main_background" 
    android:minHeight="50dip" 
    android:orientation="vertical" 
    android:padding="@dimen/screenPromoTaskRootPadding" > 

    <TextView 
     android:id="@+id/accordionTitle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="10dip" 
     android:layout_toLeftOf="@+id/accordionIndicator" 
     android:background="@color/accordionOrangeBackColor" 
     android:paddingLeft="2dip" 
     android:paddingRight="2dip" 
     android:textColor="@color/blackTextColor" 
     android:textSize="@dimen/accordMainTextSize" /> 

    <ImageView 
     android:id="@+id/accordionIndicator" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:src="@drawable/arrow_up_np" /> 

</RelativeLayout> 

和活動。 adaptiveDataCollection只是一個包含ExpandableListAdapter數據的List。它也是Accordion實現的一個片段,因此列表組將在選擇後摺疊其他元素。

ExpandableListView accordion = (ExpandableListView) findViewById(R.id.accordion); 
accordion.setOnGroupClickListener(this); 

@Override 
public boolean onGroupClick(ExpandableListView paramExpandableListView, View paramView, int paramInt, long paramLong) { 
    ImageView icon=(ImageView)paramView.findViewById(R.id.accordionIndicator); 
    for (int i = 0; i < adapterDataCollection.size(); i++) { 
     if (i == paramInt) { 
      if (paramExpandableListView.isGroupExpanded(i)) { 
       paramExpandableListView.collapseGroup(i); 
       icon.setImageResource(R.drawable.arrow_up_np); 
      } else { 
       paramExpandableListView.expandGroup(i); 
       icon.setImageResource(R.drawable.arrow_down_np); 
      } 
     } else { 
      paramExpandableListView.collapseGroup(i); 
      icon.setImageResource(R.drawable.arrow_up_np); 
     } 
    } 
    paramExpandableListView.invalidate(); 
    return true; 
} 
1

可以通過[層列表] ​​

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item 
     android:bottom="2dp" 
     android:drawable="@drawable/shrink" 
     android:top="2dp"/> 

</layer-list> 

選擇

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:drawable="@drawable/layer_shrink" android:state_expanded="true"/> 
1

應該使用9補丁圖像爲箭頭設置指示器的高度。你可以參考下圖。

right_arrow_9_patch_image

和向下箭頭則可以使用下面的圖片

down_arrow_9_patch_image

唐`忘記追加 「9" 。到圖像名稱,比如 」 your_image_name.9 。png