Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Expandable Listview SetIndicatorBounds are not working in Kitkat android-4.4

Expandable Listview SetIndicatorBounds are not working in my project code.

Here is my Layout:

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|center_vertical"
android:weightSum="1.0"
>               
<ExpandableListView
    android:id="@+id/custom_list"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:dividerHeight="1dp" 
    android:layout_weight="1"
    android:paddingBottom="0dp"
    android:divider="#b5b5b5"
    />  
    </LinearLayout>

Here is my code :

lv1 = (ExpandableListView) findViewById(R.id.custom_list);

DisplayMetrics metrics = new DisplayMetrics();

getWindowManager().getDefaultDisplay().getMetrics(metrics);

int width = metrics.widthPixels; 

lv1.setIndicatorBounds(width - GetPixelFromDips(50), width - GetPixelFromDips(10));


public int GetPixelFromDips(float pixels) {

    // Get the screen's density scale 

    final float scale = getResources().getDisplayMetrics().density;

    // Convert the dps to pixels, based on density scale

    return (int) (pixels * scale + 0.5f);

}

My Moto G kitkat device width is 720 . But setIndicatorBounds did not seems to be worked out in my Kitkat device .

Any help will be appreciated.

Thanks,

like image 301
Eldho NewAge Avatar asked Jan 10 '23 22:01

Eldho NewAge


1 Answers

try this:

if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
   mListView.setIndicatorBounds(myLeft, myRight);
} else {
   mListView.setIndicatorBoundsRelative(myLeft, myRight);
}

reference

like image 56
Rat-a-tat-a-tat Ratatouille Avatar answered Jan 17 '23 15:01

Rat-a-tat-a-tat Ratatouille