【问题标题】:expand animation issue of the last item in ListView android展开ListView android中最后一项的动画问题
【发布时间】:2014-11-25 00:29:08
【问题描述】:

我使用 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 的最后一项向下扩展,因此,如果不向上滚动,我无法看到最后一项的全部内容。

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

有什么办法可以解决吗?

【问题讨论】:

    标签: android listview


    【解决方案1】:

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

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

    或者有时你必须这样做:

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

    【讨论】:

    • 我试图这样做的是扩展 Fragment,而不是 ListActivity。所以我不能使用 setSelection 方法。有没有其他方法可以尝试?
    • 是的,但是...当我尝试时,程序说,“方法 setSelection(int) 未定义为 PullToRefreshListView 类型”
    • 哦!所以您使用的是自定义列表视图库,这就是您找不到该方法的原因,您会检查并告诉我您的 PullToRefreshListView 扩展了哪个 android 视图吗?
    • PullToRefreshListView extends PullToRefreshAdapterViewBase PullToRefreshAdapterViewBase extends PullToRefreshBase PullToRefreshBase extends LinearLayout ;那么它最终扩展了线性布局吗?
    • 好的,这就是问题所在,您的 ListView 最终会扩展 LinearLayout 这就是为什么没有这种方法的原因,让我检查一下我是否得到了有用的东西,我认为您应该检查所有方法该库提供的,也许有一些具有类似功能的方法
    猜你喜欢
    • 2012-09-25
    • 2018-09-11
    • 1970-01-01
    • 2017-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多