我已经为我的ListView启用了快速滚动功能,而且它表现得相当奇怪。当我用手势拖动ListView(即正常滚动)时,滚动按预期工作。
然而,当我从快速滚动旋钮滚动ListView时,滚动区域的底部有一个“间隙”。也就是说,当我从ListView的顶部拖动到它的底部时,滚动区域在旋钮之前到达底部!所以在旋钮的滚动区域底部有一个“死区”...当我拖动这个“死区”时,滚动根本不起作用。
我意识到这有点模糊,因为我甚至没有发布任何代码,但也许有人遇到了同样的问题并且知道可能会导致这种行为的原因。
编辑: 这是一些代码,我真的很困惑这个问题。如果您需要查看更多代码,请询问。
public class ChatFragment extends Fragment implements Chat.Listener {
private MessageAdapter messages;
// ChatArea is nothing more but a subclass of ListView
// which adds code to onDraw-method
private ChatArea area;
private EditText field;
private Chat chat;
public ChatFragment() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
messages = new MessageAdapter(getActivity());
String ID = getArguments().getString("chatID");
chat = Chat.findChatByID(ID);
if (chat == null) {
throw new RuntimeException("Could not find chat for Fragment!");
}
// This works just fine! If I add, say 500 test rows into the Chat,
// instead of waiting them to come from the server,
// the knob works perfectly.
messages.addAll(chat.getRows());
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// initialization code here
......
....
...
chat.addListener(this);
}
// Chat fires this event when it receives a message
// (comes from a non-UI thread)
@Override
public void rowInserted(Chat chat, ChatRow row) {
// This seems to be part of the problem... when I receive messages
// from the chat server, and the fast scroll will be enabled,
// the scrollbar knob does not work correctly!
insertRow(row);
}
public void insertRow(final ChatRow row) {
area.post(new Runnable() {
@Override
public void run() {
messages.add(row);
}
});
}
private class MessageAdapter extends BaseAdapter {
private List<ChatRow> messages = new ArrayList<ChatRow>();
private Context context;
public MessageAdapter(Context context) {
this.context = context;
}
public void add(ChatRow row) {
messages.add(row);
notifyDataSetChanged();
}
public void addAll(List<ChatRow> rows) {
messages.addAll(rows);
notifyDataSetChanged();
}
public void removeAll() {
messages.clear();
notifyDataSetChanged();
}
@Override
public int getCount() {
return messages.size();
}
@Override
public boolean isEnabled(int position) {
return false;
}
@Override
public Object getItem(int position) {
return messages.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// lots of code here, the bug shouldn't be here
}
}
}