main.xml:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >    <Button  android:id="@+id/btn_scroll_up" android:text="向上滚动" android:layout_width="fill_parent" android:layout_height="wrap_content" />    <Button  android:id="@+id/btn_scroll_down" android:text="向下滚动" android:layout_width="fill_parent" android:layout_height="wrap_content" />    <Button  android:id="@+id/btn_scroll_stop" android:text="停止滚动" android:layout_width="fill_parent" android:layout_height="wrap_content" />    <ListView android:id="@+id/listview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#00000000">    </ListView></LinearLayout>

item.xml:

<?xml version="1.0" encoding="UTF-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="40dp">    <TextView android:id="@+id/tv" android:layout_width="fill_parent" android:layout_height="40dp"/></LinearLayout>

Adapter.java:

package cn.guet.levide;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.TextView;public class Adapter extends BaseAdapter {    private Context context;    public Adapter(Context context)    {        this.context = context;    }    @Override    public int getCount()    {        return 40;    }    @Override    public Object getItem(int position)    {        return null;    }    @Override    public long getItemId(int position)    {        return 0;    }    class ViewHolder    {        TextView tv;    }    @Override    public View getView(int position, View convertView, ViewGroup parent)    {        ViewHolder holder = null;        if(convertView == null)        {            holder = new ViewHolder();            LayoutInflater inflater = LayoutInflater.from(context);            convertView = inflater.inflate(R.layout.item, null);            holder.tv = (TextView)convertView.findViewById(R.id.tv);            convertView.setTag(holder);        }        else        {            holder = (ViewHolder)convertView.getTag();        }        holder.tv.setText((position + 1) + ". " + "hello friends.");        return convertView;    }}

MainActivity.java:

package cn.guet.levide;import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ListView;public class MainActivity extends Activity implements OnClickListener{    private Button btn_up,btn_down,btn_stop;    private ListView listview;    private Adapter adapter;    @Override    public void onCreate(Bundle savedInstanceState)     {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        findBy();        init();    }    private void init()    {        btn_up.setOnClickListener(this);        btn_down.setOnClickListener(this);        btn_stop.setOnClickListener(this);        adapter = new Adapter(this);        listview.setAdapter(adapter);    }    private void findBy()    {        btn_up = (Button)findViewById(R.id.btn_scroll_up);        btn_down = (Button)findViewById(R.id.btn_scroll_down);        btn_stop = (Button)findViewById(R.id.btn_scroll_stop);        listview = (ListView)findViewById(R.id.listview);    }    @Override    public void onClick(View v)    {        switch(v.getId())        {        case R.id.btn_scroll_down:            listScrollDown();            break;        case R.id.btn_scroll_up:            listScrollUp();            break;        case R.id.btn_scroll_stop:            listScrollOff();            break;        }    }    Handler handler = new Handler()    {        @Override        public void handleMessage(Message msg)        {            handler.removeCallbacks(run_scroll_down);            handler.removeCallbacks(run_scroll_up);        }    };    public void listScrollUp()    {        listScrollOff();        handler.postDelayed(run_scroll_up, 0);    }    public void listScrollDown()    {        listScrollOff();        handler.postDelayed(run_scroll_down, 0);    }    public void listScrollOff()    {        handler.removeCallbacks(run_scroll_down);        handler.removeCallbacks(run_scroll_up);    }    Runnable run_scroll_up = new Runnable()    {        @Override        public void run()        {            listview.smoothScrollBy(1, 10);            handler.postDelayed(run_scroll_up, 10);        }    };    Runnable run_scroll_down = new Runnable()    {        @Override        public void run()        {            listview.smoothScrollBy(-1, 10);            handler.postDelayed(run_scroll_down, 10);        }    };}

更多相关文章

  1. android 搞定标题随scrollview滑动变色
  2. Android布局 屏幕滚动方法 ScrollView
  3. 仿Google应用动态隐藏显示状态栏
  4. [控件]SeekBar拖动条
  5. ScrollView 滚动到最后/前/上/下
  6. android 可以控制速度的跑马灯
  7. android EditText 自动滚动条 显示最新内容
  8. android srcollview按钮顶部停留
  9. Android自动滚动 轮播循环的ViewPager

随机推荐

  1. Android(安卓)玩转PathMeasure之自定义支
  2. 【原】[webkit移动开发笔记]之兼容iPhone
  3. Android--设置软键盘的显示和隐藏
  4. Android中截图(surfaceView)
  5. Android系统篇之----Android中的run-as命
  6. 【转发】Android(安卓)Metro风格的Launch
  7. Android(安卓)Studio 模板用法与自定义模
  8. android构建自定义的视图组件onMeasure
  9. Android中资源文件(非代码部分)的使用概
  10. Android(安卓)播放网络视频,视频流的处理