Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

expandable listview indicator display title height?

I have using a expandable listview with Group indicator display right side of the list, in this i have title name is single line my output like this

enter image description here

in above image my indicator is looking good. in the below image my indicator looking not good it expand, why this happen

enter image description here

here is my code

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

xml is

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

group_indicator.xml is

<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>

Any one have idea help this one........

like image 591
NagarjunaReddy Avatar asked Apr 24 '13 12:04

NagarjunaReddy


1 Answers

I solve this problem more complex way but it works:

Fragment of layout file with expandable list:

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

Layout for list group element

<?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>

and in Activity. adaptedDataCollection was just a List which contains data for ExpandableListAdapter. Also it is fragment of implementation of Accordion so list group will collapse other elements after one selected.

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;
}
like image 132
Viacheslav Avatar answered Oct 15 '22 20:10

Viacheslav