scrollBy无法在自定义适配器中工作

时间:2014-06-15 08:07:42

标签: android expandablelistview horizontalscrollview custom-adapter

我有一个自定义的ExpandableListView,它的子布局包含一个Horizo​​ntalScrollView,我在自定义适配器getChildView()中以编程方式填充,我的问题是当我在getChildView中调用它时,scrollBy()函数似乎不起作用( )

  `        @Override
        public View getChildView(final int groupPosition, final int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {

    if (convertView == null) {
    LayoutInflater infalInflater = (LayoutInflater) this._context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    convertView = infalInflater.inflate(R.layout.custom_child, null);
     }

    final HorizontalScrollView scrollView = (HorizontalScrollView) convertView
            .findViewById(R.id.horizontalScrollView1);
    final ImageButton rightBt = (ImageButton) convertView
            .findViewById(R.id.imageButton2);
    final ImageButton leftBt = (ImageButton) convertView
            .findViewById(R.id.imageButton1);

    rightBt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            scrollView.smoothScrollBy(ballD + ballM + 3, 0);

        }
    });

    leftBt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            scrollView.smoothScrollBy(-(ballD + ballM + 3), 0);
        }
    });     
            fillScrollView();
    scrollView.post(new Runnable() {

                    @Override
                    public void run() {
                        // TODO Auto-generated method stub

                            scrollView.scrollBy(ballD + ballM+3, 0);

                    }
                });
            return convertView;
}

`

滚动适用于右键和左键单击的情况,但在外面没有效果。我无法理解原因。

0 个答案:

没有答案