1 package com.xqx.fight; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.view.Menu; 6 import android.view.MotionEvent; 7 import android.view.View; 8 import android.view.View.OnTouchListener; 9 import android.widget.ArrayAdapter; 10 import android.widget.ListView; 11 12 public class MainActivity extends Activity { 13 14 private ListView listView; 15 private ArrayAdapter<String > adapter; 16 17 @Override 18 protected void onCreate(Bundle savedInstanceState) { 19 super.onCreate(savedInstanceState); 20 setContentView(R.layout.activity_main); 21 22 listView = (ListView) findViewById(R.id.listView); 23 adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); 24 for(int i=0;i<20;i++) 25 { 26 adapter.add("列表项:"+i); 27 } 28 listView.setAdapter(adapter); 29 30 listView.setOnTouchListener(new OnTouchListener() { 31 32 @Override 33 public boolean onTouch(View v, MotionEvent event) { 34 //getParent().requestDisallowInterceptTouchEvent(true) 不允许父层拦截或干扰本控件 35 listView.getParent().requestDisallowInterceptTouchEvent(true); 36 return false; 37 } 38 }); 39 } 40 41 } 42 43 MainActivity.class
MainActivity
滑动listView的时候可以滑动 滑动listView之外时整个屏幕会滑动
时间: 2024-10-12 20:46:34