根据对我之前问题的回答,我正在制作一个高度定制的滚动列表,并且我希望捕获子视图偏移量(让基本的 Android 功能处理在过度滚动时的轻弹和弹跳等)。
然而,偏移量总是返回 0。想法非常受欢迎
package com.example.svexample
import android.annotation.TargetApi;
import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.widget.ScrollView;
public class ScrollViewTest {
private static final String TAG = ScrollViewTest.class.getSimpleName();
private ScrollView sv;
private View v;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public ScrollViewTest(Context context) {
v = new View(context);
v.setBackgroundColor(Color.BLUE);
v.setBottom(800); v.setRight(400);
sv = new ScrollView(context);
sv.setBackgroundColor(Color.RED);
sv.setBottom(400); sv.setRight(400);
//The next two lines don't seem to help...
//LayoutParams lp = new LayoutParams(400, 600);
//sv.setLayoutParams(lp);
sv.addView(v);
}
public void draw(Canvas canvas){
sv.draw(canvas);
v.draw(canvas);
Log.d(TAG, "Scroll is: " + sv.getScrollY());
}
}