NagarjunaReddy
NagarjunaReddy

Reputation: 8645

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

Upvotes: 6

Views: 4349

Answers (4)

varotariya vajsi
varotariya vajsi

Reputation: 4041

You should use 9 patch image for arrow. You can refer bellow image.

right_arrow_9_patch_image

and for down arrow you can use below image

down_arrow_9_patch_image

Don`t forget to append ".9" to the image name like "your_image_name.9.png"

Upvotes: 2

kyo
kyo

Reputation: 11

you can set indicator height by [layer-list] http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList

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

selector

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

Upvotes: 1

AlexBcn
AlexBcn

Reputation: 2460

Look the view that your are using on your custom_group_layout.xml when you inflate it on your getGroupView() of your adapterClass. The view of your indicator maybe has a fill_parent and that's why your item is stretching his icon when you group contains more lines of text.

An example

Upvotes: 0

Viacheslav
Viacheslav

Reputation: 5593

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

Upvotes: 2

Related Questions