如果我的 ListView 不会处于滚动模式(因为屏幕上的项目很少),那么我想要它 android:stackFromBottom="false"
但如果我的 ListView 开始滚动(有足够的项目可以滚动),那么我想通过我的代码 android:stackFromBottom="true"
。我怎样才能过去?希望你能找到我。
最佳答案
比较 getLastVisiblePosition()
与 getCount()
在 Runnable 中查看整个 ListView 在绘制后是否适合屏幕。您还应该检查最后一个可见行是否完全适合屏幕。
创建可运行的:
ListView listView;
Runnable fitsOnScreen = new Runnable() {
@Override
public void run() {
int last = listView.getLastVisiblePosition();
if(last == listView.getCount() - 1 && listView.getChildAt(last).getBottom() <= listView.getHeight()) {
// It fits!
}
else {
// It doesn't fit...
}
}
};
在 onCreate()
中将您的 Runnable 放入 ListView 的处理程序中:
listView.post(fitsOnScreen);
关于Android:如何获取ListView是否处于滚动模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22114747/