Because of the project's reason, it is necessary for the ListView to select the item as the middle of the currently visible item, but the method found on the web is too cumbersome, so try it yourself.
Private ListView TESTLV;
private int Center;
private int first;
Testlv.setonitemclicklistener (this);
Testlv.setonscrolllistener (this);
@Override public
void Onitemclick (adapterview<?> adapterview, view view, final int i, long l) {
if (i > C Enter) {
// testlv.setselection (i-center);
Testlv.post (New Runnable () {
@Override public
void Run () {
if (I-center > First) {
Testlv.setselection (I-center);
} else {
testlv.smoothscrolltoposition (i-center);}}}
);
} else {
Testlv.smoothscrolltoposition (0);
}
}
@Override public
void onscrollstatechanged (Abslistview abslistview, int. i) {
}
@Override
public void Onscroll (Abslistview abslistview, int i, int i1, int i2) {First
= i;
Center = I1/2;
}
If you use SetSelection (), then the ListView jumps directly to the specified entry, there is no animation in the middle, and a scrolling animation is used with Smoothscrolltoposition ().
However, when you use the Smoothscrolltoposition () method, if you select below the currently visible entry (for example, the total number of currently visible entries is 10, you select the 8th visible entry), then the ListView does not scroll up, specifically I do not study, Let's make it work, and if anyone has the heart to study the problem, we welcome the discussion.