扩展ListView android中最后一项的动画问题

时间:2014-11-24 16:25:16

标签: android listview

我使用

在ListView中应用展开动画
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
    super.applyTransformation(interpolatedTime, t);

    if (interpolatedTime < 1.0f) {

        // Calculating the new bottom margin, and setting it
        mViewLayoutParams.bottomMargin = mMarginStart
                + (int) ((mMarginEnd - mMarginStart) * interpolatedTime);

        // Invalidating the layout, making us seeing the changes we made
        mAnimatedView.requestLayout();

    // Making sure we didn't run the ending before (it happens!)
    } else if (!mWasEndedAlready) {
        mViewLayoutParams.bottomMargin = mMarginEnd;
        mAnimatedView.requestLayout();

        if (mIsVisibleAfter) {
            mAnimatedView.setVisibility(View.GONE);
        }
        mWasEndedAlready = true;
    }
}

在这里,当我尝试单击ListView的最后一项时,我的Listview的最后一项向下扩展,所以我看不到最后一项而不向上滚动。

换句话说,如果我点击最后一个,我希望我的焦点在最后一个项目的底部(自动滚动),这样我就可以立即看到最后一个的全部内容。

有什么办法可以解决吗?

1 个答案:

答案 0 :(得分:0)

也许这会有所帮助:(首先检查用户是否点击了最后一项)

listView.setSelection(ListAdapter.getCount() - 1);

或者有时你必须做这样的事情:

listView.post(new Runnable()
{
    @Override
    public void run()
    {
        listView.setSelection(ListAdapter.getCount() - 1);                                                                  
    }
});
相关问题