我创建了自己的类,它扩展了ScrollView但滚动条消失了。滚动页面时如何显示滚动条。这是我的班级代码:
package se.nindev.restaurant.views;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;
public class ScrollViewer extends ScrollView {
private float mLastX;
private float mLastY;
private float mDiffX;
private float mDiffY;
public ScrollViewer(Context context) {
this(context, null);
}
public ScrollViewer(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ScrollViewer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
// @Override
// public boolean dispatchTouchEvent(MotionEvent ev){
// return super.dispatchTouchEvent(ev);
// }
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// reset difference values
mDiffX = 0;
mDiffY = 0;
mLastX = ev.getX();
mLastY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
mDiffX += Math.abs(curX - mLastX);
mDiffY += Math.abs(curY - mLastY);
mLastX = curX;
mLastY = curY;
// don't intercept event, when user tries to scroll horizontally
if (mDiffX > mDiffY) {
return false;
}
}
return super.onInterceptTouchEvent(ev);
}
}
在滚动视图中我在页面中间滚动时,比滚动视图中的页面中间滚动有更多的元素,但在我的课程中,我没有那种效果。如何将普通滚动视图中的所有效果添加到我的班级?
编辑:好的我添加了滚动条:android:scrollbars="vertical"
但仍然不知道如何添加此grafic效果
答案 0 :(得分:3)
ScrollView scrollView = new ScrollView(getContext());
scrollView.setVerticalScrollBarEnabled(true);
scrollView.setHorizontalScrollBarEnabled(true);
答案 1 :(得分:0)
android:background="@color/white"
android:fadingEdge="vertical"
我们需要在白色上更改背景滚动视图并使用渐变边缘