Skip to content Skip to sidebar Skip to footer

How To Change Expandablelistview Group Indicator Position?

I want to change the ExpandableListView group indicator to right with padding. I used custom adapter to load data to ExpandableListView. This is my ExpandableListView xml.

Solution 1:

setIndicatorBounds(int, int) does not work properly for Android 4.3. They introduced a new method setIndicatorBoundsRelative(int, int) which works ok for 4.3.

publicintGetPixelFromDips(float pixels) {
    // Get the screen's density scale finalfloatscale= getResources().getDisplayMetrics().density;
    // Convert the dps to pixels, based on density scalereturn (int) (pixels * scale + 0.5f);
}

@OverridepublicvoidonWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    DisplayMetricsmetrics=newDisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    intwidth= metrics.widthPixels; 
    if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
        explvList.setIndicatorBounds(width-GetPixelFromDips(35), width-GetPixelFromDips(5));
    } else { 
        explvList.setIndicatorBoundsRelative(width-GetPixelFromDips(35), width-GetPixelFromDips(5));
    }
}

Solution 2:

privatevoidsetGroupIndicatorToRight() {
    /* Get the screen width */DisplayMetricsdm=newDisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        intwidth= dm.widthPixels;
        expandableList.setIndicatorBounds(width - getDipsFromPixel(35), width - getDipsFromPixel(5));
    }
    // Convert pixel to dippublicintgetDipsFromPixel(float pixels) {
        // Get the screen's density scalefinalfloatscale= getResources().getDisplayMetrics().density;
        // Convert the dps to pixels, based on density scalereturn (int) (pixels * scale + 250.5f);
    }

Solution 3:

If you want to move indicator to right Just create a dimen in res folder. It will be like that:

<?xml version="1.0" encoding="utf-8"?><resources><dimenname="my_value">350dp</dimen></resources>

Then in the <ExpandableListView/> add like that:

<ExpandableListView...android:indicatorLeft="@dimen/my_value".../>

You can change the dp according to device settings

Post a Comment for "How To Change Expandablelistview Group Indicator Position?"