我想听ScrollView看它是否滚动.我使用OnTouchListener,效果很好.但是当我想使用OnKeyListener添加与轨迹球的兼容性或重写OnKeydown方法时,它无法工作.看起来像焦点的儿童按钮导致问题.
解决此问题的任何解决方案或解决方法?任何帮助表示赞赏.
以下是一些重现我的问题的演示代码:
public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ScrollView scrollView = (ScrollView) findViewById(R.id.scroll_view);
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main_layout);
LinearLayout.LayoutParams wrapParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
for (int i = 0; i < 100; i++) {
MyItem item = (MyItem) LayoutInflater.from(this).inflate(R.layout.item, null);
item.setParent(scrollView);
item.setBackgroundColor(Color.WHITE);
item.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
mainLayout.addView(item, wrapParams);
}
scrollView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// can go into here
}
});
scrollView.setOnKeyListener(new OnKeyListener() {
@Override …Run Code Online (Sandbox Code Playgroud)