[英]Using both a CardScrollView and a ScrollView
I have a CardScrollView with multiple cards. 我有一张带多张卡的CardScrollView。 Swiping left and right moves between the cards.
向左和向右滑动可在卡片之间移动。
Some of the cards have a lot of content on them. 有些卡片上有很多内容。 I used a ScrollView so the user can scroll through the card to see the content.
我使用了ScrollView,因此用户可以滚动卡片以查看内容。
Glass doesn't know whether it should scroll to a different card or scroll on the card it is on when the user swipes their finger for obvious reasons. 当用户滑动手指时,Glass不知道是否应该滚动到另一张卡片或滚动它所在的卡片上有明显的原因。 It chooses to scroll to a different card.
它选择滚动到另一张卡。
To differentiate, I want to use the GestureDetector to make a one finger scroll scroll cards, and a two finger scroll scroll on the selected card. 为了区分,我想使用GestureDetector制作单指滚动滚动卡片,并在所选卡片上滚动两个手指滚动。 Seems easy enough, so I made the createGestureDetector() method and put if statements for each case.
看起来很简单,所以我创建了createGestureDetector()方法并为每个case添加了if语句。
Now I have a problem...I do not know how to tell the CardScrollView to advance or go back a card, and I dont know how to make the ScrollBody scroll based on the gesture. 现在我有一个问题...我不知道如何告诉CardScrollView推进或回卡,我不知道如何根据手势制作ScrollBody滚动。
I looked through all of the available methods and nothing stuck out to me as particularly helpful. 我查看了所有可用的方法,并没有任何问题对我来说特别有帮助。 Does anyone have any idea how to do this?
有谁知道怎么做?
Bonus question: I saw a lot of "dispatch" commands, like dispatchGenericMotionEvent. 奖金问题:我看到了很多“dispatch”命令,比如dispatchGenericMotionEvent。 What do dispatch methods do?
派遣方法有什么作用?
EDIT: 编辑:
Here is my code after Jean Vacca's suggestion: 以下是Jean Vacca建议之后的代码:
private GestureDetector createGestureDetector(Context context) {
GestureDetector gestureDetector = new GestureDetector(context);
gestureDetector.setFingerListener(new GestureDetector.FingerListener() {
@Override
public void onFingerCountChanged(int previousCount, int currentCount) {
if(currentCount == 2){
mCardScrollView.deactivate();
}else{
mCardScrollView.activate();
}
}
});
return gestureDetector;
}
and the xml for my views is: 我的观点的xml是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:id="@+id/scrollBody"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="false">
<LinearLayout
android:id="@+id/scrollLinearLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
</ScrollView>
</RelativeLayout>
Which is filled with TextViews in this code segment located in the CardScrollAdapter: 在CardScrollAdapter中的此代码段中填充了TextView:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
int nextID = 3;
if (convertView == null) {
convertView = View.inflate(context, R.layout.my_card, null);
holder = new ViewHolder();
MyClass mine = mMyList.get(position);
LinearLayout ll = (LinearLayout)convertView.findViewById(R.id.scrollLinearLayout);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
holder.name = new TextView(this.context);
holder.name.setId(nextID);
nextID++;
holder.name.setTextSize(50);
holder.name.setText(mine.getName());
holder.name.setLayoutParams(lp);
holder.name.setGravity(Gravity.CENTER);
ll.addView(holder.name);
holder.infoTextViews = new ArrayList<TextView>(mine.getInfo().size());
for(int i = 0; i < mine.getInfo().size(); i++)
{
holder.infoTextViews.add(new TextView(this.context));
TextView tv = holder.infoTextViews.get(i);
tv.setId(nextID);
nextID++;
tv.setTextSize(24);
tv.setText(mine.getInfo().get(i));
tv.setLayoutParams(lp);
tv.setGravity(Gravity.CENTER);
ll.addView(tv);
}
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
I hope these edits help! 我希望这些编辑有所帮助!
I had a similar problem on my project. 我的项目遇到了类似的问题。 To resolve it, I had to handle the "onFingerCountChanged" in the GestureDetector and desactivate the CardScrollView when i have 2 fingers count.
为了解决这个问题,我必须在GestureDetector中处理“onFingerCountChanged”并在我有2个手指计数时停用CardScrollView。 So when I use one finger the cardscrollview scroll normaly and when I use two finger on can scroll in my card using the gestureDetector.
因此,当我使用一根手指时,cardscrollview滚动正常,当我使用两根手指时,可以使用gestureDetector在我的卡片中滚动。
You code should look something like this : 你的代码应该是这样的:
gestureDetector.setFingerListener(new GestureDetector.FingerListener() {
@Override
public void onFingerCountChanged(int previousCount, int currentCount) {
if(currentCount == 2){
yourCardScrollView.deactivate();
}else{
yourCardScrollView.activate();
}
}
....
}
EDIT: I notice that my first answer is not work. 编辑:我注意到我的第一个答案是行不通的。 I have another one.
我有另一个。 You can use following code in your Activity.
您可以在Activity中使用以下代码。
@Override
public boolean dispatchGenericMotionEvent(MotionEvent ev) {
if (ev.getPointerCount() > 1) {
return true;
}
return super.dispatchGenericMotionEvent(ev);
}
When dispatchGenericMotionEvent actives, detect if pointer is greater than one (muit-touch), return true and consume it. 当dispatchGenericMotionEvent处于活动状态时,检测指针是否大于1(muit-touch),返回true并使用它。
I tested, but still have bug. 我测试过,但仍然有bug。 https://code.google.com/p/google-glass-api/issues/detail?id=632
https://code.google.com/p/google-glass-api/issues/detail?id=632
Reply me if it works. 如果有效,请回复我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.