gpt4 book ai didi

android - 如何禁用 SwipeRefreshLayout 中的触摸事件?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:14:20 27 4
gpt4 key购买 nike

我使用 Google 的 SwipeRefreshLayout。我有几个问题。

  1. 如何在触摸屏处于 Activity 状态时阻止触摸屏 onRefresh()
  2. 如何在更新期间在屏幕的旋转中心而不是顶部取得进展?

    swipeLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_status_info);
    swipeLayout.setColorSchemeColors(Color.RED, Color.GREEN, Color.BLUE, Color.CYAN);
    swipeLayout.setOnRefreshListener(this);


    @Override
    public void onRefresh() {
    clearTable(holidayTable);
    clearTable(cityayTable);
    setData();
    }

最佳答案

  1. 如果您想阻止某些 View (blockedView) 在刷新期间获取触摸事件,您可以在 OnTouchListener 中使用该事件:

    @Override
    public void onRefresh() {
    clearTable(holidayTable);
    clearTable(cityayTable);
    setData();
    refreshing = true;
    }
    ...

    blockedView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    //consuming the touch
    if (refreshing) return true;
    //letting the touch propagate
    else return false;
    }
    });
  2. 使用此方法以像素为单位设置所需的偏移量:

    swipeLayout.setProgressViewOffset(true, 0, offset);

关于android - 如何禁用 SwipeRefreshLayout 中的触摸事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27520240/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com