Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android - ScrollView添加提示Arrow(箭頭)

Android - ScrollView添加提示Arrow(箭頭)

編輯:關於Android編程

ScrollView添加提示Arrow(箭頭)

 

 

 

ScrollView的滑動功能中,需要給用戶提示,可以滑動,可以添加兩個箭頭。

定制ScrollView,創建監聽器IScrollStateListener接口:

    private IScrollStateListener scrollStateListener;
    public void setScrollStateListener(IScrollStateListener listener) {
        scrollStateListener = listener;
    }

    public interface IScrollStateListener {
        void onScrollMostLeft();
        void onScrollFromMostLeft();
        void onScrollMostRight();
        void onScrollFromMostRight();
    }


在監聽滑動的時候,調用監聽滑動事件(onScrollChanged)
    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);

        if (scrollStateListener != null) {
            if (l == 0) {
                scrollStateListener.onScrollMostLeft();
            } else if (oldl == 0) {
                scrollStateListener.onScrollFromMostLeft();
            }

            int mostRightL = this.getChildAt(0).getWidth()-getWidth();

            if (l >= mostRightL) {
                scrollStateListener.onScrollMostRight();
            } else if (oldl >= mostRightL && l < mostRightL) {
                scrollStateListener.onScrollFromMostRight();
            }
        }
    }


在使用滑動條時,給監聽事件,傳遞具體事務:
        final ImageView leftArrow = (ImageView)view.findViewById(R.id.doctor_gather_imageview_leftarrow);
        final ImageView rightArrow = (ImageView)view.findViewById(R.id.doctor_gather_imageview_rightarrow);

        AutoHorizontalScrollView scrollView = (AutoHorizontalScrollView)view.findViewById(R.id.doctor_gather_scrollview);
        scrollView.setScrollStateListener(new AutoHorizontalScrollView.IScrollStateListener() {
            @Override
            public void onScrollMostLeft() {
                Log.e(DEBUG + TAG, 滑動條最左面);
                leftArrow.setVisibility(View.INVISIBLE);
                rightArrow.setVisibility(View.VISIBLE);
            }

            @Override
            public void onScrollFromMostLeft() {
                Log.e(DEBUG+TAG, 滑動條離開最左面);
                leftArrow.setVisibility(View.VISIBLE);
                rightArrow.setVisibility(View.VISIBLE);
            }

            @Override
            public void onScrollMostRight() {
                Log.e(DEBUG+TAG, 滑動條最右面);
                leftArrow.setVisibility(View.VISIBLE);
                rightArrow.setVisibility(View.INVISIBLE);
            }

            @Override
            public void onScrollFromMostRight() {
                Log.e(DEBUG+TAG, 滑動條離開最右面);
                leftArrow.setVisibility(View.VISIBLE);
                rightArrow.setVisibility(View.VISIBLE);
            }
        });


即可。
參考:http://stackoverflow.com/questions/9062227/how-to-set-images-for-scrollview-instead-of-fading-edges



/

 

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved