ScrollView嵌入ListView

来源:互联网 发布:连接网络打印机 编辑:程序博客网 时间:2024/05/21 12:41
public class MainActivity extends Activity{    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        ArrayList<String> data = new ArrayList<String>();        for (int i=0;i<50;i++){            data.add("data"+i);        }        setContentView(R.layout.main_activity);        ListView list = (ListView) findViewById(R.id.list);        ArrayAdapter adapter = new ArrayAdapter(getApplication(),R.layout.support_simple_spinner_dropdown_item,data);        list.setAdapter(adapter);        //对手势进行监听        list.setOnTouchListener(new View.OnTouchListener() {            @Override            public boolean onTouch(View v, MotionEvent event) {                switch (event.getAction()){                    case (MotionEvent.ACTION_DOWN):                        v.getParent().requestDisallowInterceptTouchEvent(true);//监听action_down事件                        break;                    case (MotionEvent.ACTION_CANCEL):                        v.getParent().requestDisallowInterceptTouchEvent(false);                }                return false;            }        });    }}


//布局

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent">    <ScrollView        android:layout_width="match_parent"        android:layout_height="match_parent"        android:background="#ffee90">        <LinearLayout            android:orientation="vertical"            android:layout_width="match_parent"            android:layout_height="match_parent"            android:layout_gravity="center">            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ListView                android:id="@+id/list"                android:layout_width="match_parent"                android:layout_height="100dp"                android:background="#ffc012">            </ListView>            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />            <ImageView                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:src="@mipmap/ic_launcher" />        </LinearLayout>    </ScrollView></LinearLayout>


0 0
原创粉丝点击