Android:Gallery 中的 ListViews - 如何像 GTalk 中那样滚动、单击和滑动?

发布于 2024-11-01 15:38:15 字数 663 浏览 4 评论 0原文

我正在编写一个 Android 应用程序,并在 Gallery 中使用 ListViews。 ListViews 代表聊天窗口。我真的希望能够在图库中的聊天窗口之间滑动,同时还能够在 ListView 中滚动或单击单个消息。 在搜索时,我在 Stackoverflow 上发现了一个人,他很友善地为这个问题提供了解决方案: Android - Gallery 内的 ListView 使滚动不平滑

他的 BetterGallery 几乎适合我。单击列表项有效,滚动列表视图有效。我目前有两个问题需要解决此实现:

1)在图库中滑动时,移动不顺畅,并且并不总是确定最终将显示哪个列表视图。

2) 您可以在同一个手指移动中同时滑动和滚动,例如对角移动手指。

作为第 2 点的注释:我正在寻找的行为类似于您可以在 GTalk 中找到的聊天窗口。在 GTalk 中,您可以一次在聊天中滚动,或在不同聊天之间滑动。这意味着如果您开始滚动,左右移动手指将不会滑动。同样,开始滑动将阻止滚动,直到您松开手指并开始新的手势。

有没有人实现了类似于 GTalk 中的工作方式?

最好的祝愿!

I am writing an Android application, and I use ListViews inside a Gallery. The ListViews represent chat windows. I would really like to be able to swipe between the chat windows in the Gallery, while also being able to scroll in the ListView or click single messages.
While searching, I found a guy here on Stackoverflow that was kind enough to provide his solution to this problem:
Android - ListView inside Gallery makes the scrolling not Smooth

His BetterGallery almost works out for me. Clicking a list item works and scrolling the list view works. I currently have two issues to iron out with this implementation:

1) When swiping in the gallery, the movement is not smooth and it is not always certain which List View it will end up displaying.

2) You can both swipe and scroll at the same time in the same finger movement by e.g. moving your finger diagonally.

As a note to point 2: The behavior I am looking for is something similar to the chat windows that you can find in GTalk. In GTalk, you can either do scrolling inside a chat, or swiping between different chats, in one movement. That means if you start scrolling, moving your finger from side to side will not swipe. Similarly, starting a swipe will block scrolling until you release the finger and start a new gesture.

Has anyone achieved something similar to how it works in GTalk?

Best wishes!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠檬心 2024-11-08 15:38:15

我也有同样的问题。解决方案并不简单。

    • 将列表视图设置为在触摸模式下不可聚焦。

    listView.setFocusableInTouchMode(false);

    • 如果您需要焦点,请从 onItemSelected 侦听器调用它。

2. - 使用 OnInterceptTouchEvent 从您的孩子那里获取触摸事件。并在onScroll和onTouchEvent中进行一些修改

    
    OnItemSelectedListener mOnItemSelected = new OnItemSelectedListener()
            {
@Override public void onItemSelected(AdapterView parent, View view, int position, long id) { view.requestFocusFromTouch(); } @Override public void onNothingSelected(AdapterView parent) {
} };

    
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        onTouchEvent(ev);
        return scrollingHorizontally;
    }

@Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if(Math.abs(distanceX)>Math.abs(distanceY) || scrollingHorizontally == true){ scrollingHorizontally = true; super.onScroll(e1, e2, distanceX, distanceY); } return scrollingHorizontally; }

@Override
public boolean onTouchEvent(MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
scrollingHorizontally = false;
break;
default:
break;
}
super.onTouchEvent(event);
return scrollingHorizontally;
}

I had have the same problem. And the solution is less than simple.

    • Set the listview to be not focusable in touch mode.

    listView.setFocusableInTouchMode(false);

    • If you need focus, call it from onItemSelected listener.

2. - Use OnInterceptTouchEvent to get Touch Events from your child. And make some modification in onScroll and onTouchEvent

    
    OnItemSelectedListener mOnItemSelected = new OnItemSelectedListener()
            {
@Override public void onItemSelected(AdapterView parent, View view, int position, long id) { view.requestFocusFromTouch(); } @Override public void onNothingSelected(AdapterView parent) {
} };

    
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        onTouchEvent(ev);
        return scrollingHorizontally;
    }

@Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if(Math.abs(distanceX)>Math.abs(distanceY) || scrollingHorizontally == true){ scrollingHorizontally = true; super.onScroll(e1, e2, distanceX, distanceY); } return scrollingHorizontally; }

@Override
public boolean onTouchEvent(MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
scrollingHorizontally = false;
break;
default:
break;
}
super.onTouchEvent(event);
return scrollingHorizontally;
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文