关闭

listview 快速拖动

标签: listviewandroidlayoutapplicationnullstring
1371人阅读 评论(0) 收藏 举报

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);
    }

   }
  });

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:181828次
    • 积分:1699
    • 等级:
    • 排名:千里之外
    • 原创:31篇
    • 转载:9篇
    • 译文:0篇
    • 评论:41条
    文章分类
    最新评论