美文网首页
Android 横向scrollView(horizontalS

Android 横向scrollView(horizontalS

作者: yunhen | 来源:发表于2019-10-10 11:53 被阅读0次

    相关文章https://blog.csdn.net/weixin_41101173/article/details/80158169

    /**
         * horizontalScrollView item点击并滑动到中间
         * @param horizontalScrollView
         * @param itemView
         */
        private void performHscrollViewItemClick(HorizontalScrollView horizontalScrollView,View itemView) {
            //------get Display's Width--------
            DisplayMetrics displayMetrics = new DisplayMetrics();
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    
            int screenWidth = displayMetrics.widthPixels;
    
            int scrollX = (itemView.getLeft() - (screenWidth / 2)) + (itemView.getWidth() / 2);
    
            //smooth scrolling horizontalScrollView
            horizontalScrollView.smoothScrollTo(scrollX, 0);
    
            //additionally we set current center textView data to our testTextView
    //        String s = "CenterLocked Item: "+((TextView)view).getText();
    //        testTextView.setText(s);
        }
    

    相关文章

      网友评论

          本文标题:Android 横向scrollView(horizontalS

          本文链接:https://www.haomeiwen.com/subject/fsvopctx.html