listview 快速拖动

ListView设置如下:

<ListView android:id="@android:id/list" android:layout_width="fill_parent"
   android:layout_height="wrap_content" android:fastScrollEnabled="true"
   android:focusable="true">

</ListView>

 

快速滑动时的现实文字:overlay.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:textSize="36sp"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/text_green"
    android:background="@drawable/receipts_select_hinter_bg"
    android:gravity="center"
/>

 

acvitity中的调用代码:

 

this.overlay = (TextView) View.inflate(this,
    R.layout.overlay, null);
  windowManager = getWindowManager();
  WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
    WindowManager.LayoutParams.TYPE_APPLICATION,
    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
      | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
    PixelFormat.TRANSLUCENT);
  lp.gravity = Gravity.TOP;
  lp.verticalMargin = 0.1f;
  lp.horizontalMargin = 0.1f;
  windowManager.addView(overlay, lp);
  overlay.setVisibility(View.INVISIBLE);

 

 

ListView拖动事件:

 

ListView.setOnScrollListener(new OnScrollListener() {
   boolean visible;

   @Override
   public void onScroll(AbsListView view, int firstVisibleItem,
     int visibleItemCount, int totalItemCount) {
    if (visible && nameStrFinal != null) {
     String name = nameStrFinal[firstVisibleItem]
       .substring(0, 1);
     overlay.setText(CommonUtil.getPYString(name));
     overlay.setVisibility(View.VISIBLE);
    }

   }

   @Override
   public void onScrollStateChanged(AbsListView view, int scrollState) {
    visible = true;
    if (scrollState == ListView.OnScrollListener.SCROLL_STATE_IDLE) {
     overlay.setVisibility(View.INVISIBLE);
    }

   }
  });

阅读更多
上一篇在做含有CheckBox的Adapter的可能会遇到的问题:
下一篇android WebView
想对作者说点什么? 我来说一句

ListView性能优化

2013年02月11日 22KB 下载

没有更多推荐了,返回首页

关闭
关闭