As regards to expandable list view, the group icon indicator is positioned to the left side, can I move the indicator and positioned it to the right? Thanks.
EDITED: Since I don't want to extend the view, I got this workaround of getting the width dynamically. Just sharing my solution.
Display newDisplay = getWindowManager().getDefaultDisplay(); int width = newDisplay.getWidth(); newListView.setIndicatorBounds(width-50, width);
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.
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
mExpandableListView.setIndicatorBounds(myLeft, myRight);
} else {
mExpandableListView.setIndicatorBoundsRelative(myLeft, myRight);
}
}
All XML solution! I found a better way of tackling this issue. This does not require you to mess with display metrics, no need to programmatically hack it.
This is what you need to do:
1) set layout direction to right-to-left
<ExpandableListView
...
android:layoutDirection="rtl" />
2) make sure your list item layout includes this (yes, you'll need custom layout):
android:gravity="left" //to adjust the text to align to the left again
android:layoutDirection="ltr" //OR this line, based on your layout
And you are good to go!
The best way to do this is below but not for all Android Version So use 2nd or third method specified below
ViewTreeObserver vto = mExpandableListView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
mExpandableListView.setIndicatorBounds(mExpandableListView.getRight()- 40, mExpandableListView.getWidth());
}
});
or this:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
mExpandableListView.setIndicatorBounds(mExpandableListView.getRight()- 40, mExpandableListView.getWidth());
}
will move that indicator to right of list view even on device and on tab also.
or you can do this in a postdelayed thread.
(new Handler()).post(new Runnable() {
@Override
public void run() {
mExpandableListView.setIndicatorBounds(mExpandableListView.getRight()- 40, mExpandableListView.getWidth());
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With