1.MainActivity布局
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<com.bwei.adapter.MyListview
android:id="@+id/lv_main_listview"
android:layout_width="fill_parent"
android:layout_height="300dp"
></com.bwei.adapter.MyListview>
<TextView
android:id="@+id/tname"
android:layout_width="fill_parent"
android:layout_height="500dp"
android:text="心若冰清,天塌不惊" />
</LinearLayout>
</ScrollView>
2.子布局
<?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"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:text="天天好心情" />
</LinearLayout>
3.MainActivity类
package com.bwei.main;
import com.bwei.adapter.MyAdapter;
import com.bwei.adapter.MyListview;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ListView;
public class MainActivity extends Activity {
private MyListview lv_main_listview;
private MyAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv_main_listview = (MyListview)findViewById(R.id.lv_main_listview);
adapter=new MyAdapter(this);
lv_main_listview.setAdapter(adapter);
}
}
4.MyAdapter类
package com.bwei.adapter;
import com.bwei.main.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
public class MyAdapter extends BaseAdapter {
Context context;
public MyAdapter(Context context) {
this.context=context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 20;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView==null){
holder=new ViewHolder();
convertView=View.inflate(context, R.layout.lv_item, null);
convertView.setTag(holder);
}else{
holder=(ViewHolder) convertView.getTag();
}
return convertView;
}
class ViewHolder{
}
}
5.MyListview类
package com.bwei.adapter;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListView;
public class MyListview extends ListView {
public MyListview(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MyListview(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MyListview(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
boolean b = super.onTouchEvent(ev);
return b;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
//
getParent().requestDisallowInterceptTouchEvent(true);
boolean b = super.dispatchTouchEvent(ev);
return true;
}
}