需要了解Google Glass中的水平拖拽反馈

时间:2014-07-15 11:33:48

标签: android google-glass google-gdk

我只是谷歌眼镜的初学者。

我读到了关于水平拖拽反馈的问题here

它说" 许多在玻璃上的内置沉浸物提供了"拉扯"向后和向前滑动时的反馈不要执行操作。"

此外,我们需要添加此代码以应用效果:

助手类:

public class TuggableView extends CardScrollView {

private final View mContentView;

/**
 * Initializes a TuggableView that uses the specified layout
 * resource for its user interface.
 */
public TuggableView(Context context, int layoutResId) {
    this(context, LayoutInflater.from(context)
            .inflate(layoutResId, null));
}

/**
 * Initializes a TuggableView that uses the specified view
 * for its user interface.
 */
public TuggableView(Context context, View view) {
    super(context);

    mContentView = view;
    setAdapter(new SingleCardAdapter());
    activate();
}

/**
 * Overridden to return false so that all motion events still
 * bubble up to the activity's onGenericMotionEvent() method after
 * they are handled by the card scroller. This allows the activity
 * to handle TAP gestures using a GestureDetector instead of the
 * card scroller's OnItemClickedListener.
 */
@Override
protected boolean dispatchGenericFocusedEvent(MotionEvent event) {
    super.dispatchGenericFocusedEvent(event);
    return false;
}

/** Holds the single "card" inside the card scroll view. */
private class SingleCardAdapter extends CardScrollAdapter {

    @Override
    public int getPosition(Object item) {
        return 0;
    }

    @Override
    public int getCount() {
        return 1;
    }

    @Override
    public Object getItem(int position) {
        return mContentView;
    }

    @Override
    public View getView(int position, View recycleView,
            ViewGroup parent) {
        return mContentView;
    }
}
}

活动类:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// was: setContentView(R.layout.main_activity);
setContentView(new TuggableView(this, R.layout.main_activity));
}

所以我的问题是:这种影响是什么以及它如何影响我们的应用程序?

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

如果愿意,此代码会创建卡片的效果,然后弹回“#34;”。类似于Android中的列表允许您向上或向下滚动列表末尾,但在用户放手后退回到列表的底部/顶部。它给人一种橡皮筋效果的幻觉。