Android - extensible Listview SetIndicatorBounds not working in Kitkat android-4.4

Extensible Listview SetIndicatorBounds do not work 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 density scale 

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

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

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

}

The width of the Myoto G kitkat device is 720. But setIndicatorBounds did not seem to work on my Kitkat device.

Any help would be appreciated.

Thank,

+4
source share
1 answer

try the following:

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

link

+9
source

Source: https://habr.com/ru/post/1533704/


All Articles