简体   繁体   English

如何将列表视图的第二行滚动到屏幕顶部

[英]How to scroll the second row of listview to top of the screen

Hello I am working on demo application where I am using listview and custom adapter. 您好,我正在开发演示应用程序,其中正在使用listview和自定义适配器。 I want to do that when I scroll the list when you come at position to 2 or 3 then that row should be on top of the screen means previous row should be hide completely. 当我滚动列表到位置2或3时,我想这样做,那么该行应位于屏幕顶部,这意味着上一行应完全隐藏。

Example I am on first row first time and started to scroll listview then comes to second when getview call with position 2 then list should only show of row 2 on the screen. 示例我第一次在第一行上,开始滚动listview,然后在位置2 getview调用时进入第二行,然后list应该只在屏幕上显示第二行。 How I can achieve this ? 我该如何实现? Please assist. 请协助。

See screenshot when I scroll then both rows appear when I even move to row 2 then first row also appears until I move up list manually. 滚动时查看屏幕截图,然后甚至在移至第2行时都显示两行,然后还会出现第一行,直到我手动向上移动列表为止。

在此处输入图片说明

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if(convertView == null) {
        LayoutInflater mInflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = mInflator.inflate(R.layout.home_list_item, parent, false);
    }

    TextView mChapterContent = (TextView) convertView.findViewById(R.id.contentTextView);

    // get the data from verse instance
    Verse verse = rowItem.get(position);

    // setting the content
    mChapterContent.setText(Html.fromHtml("<html><body style=\"text-align:justify\">" + verse.getText() + "</body></html>"));



    return convertView;
}

Thanks in advance. 提前致谢。

Judging from the state, it looks to me as a good use-case of Vertical View pager. 从状态来看,在我看来,它是Vertical View寻呼机的一个很好的用例。

Checkout these likes: 签出这些赞:

https://github.com/JakeWharton/Android-DirectionalViewPager/ https://github.com/JakeWharton/Android-DirectionalViewPager/

Android: Vertical ViewPager Android:垂直ViewPager

You can use the ListView 's setSelection feature to scroll to a particular item in the list as follows... 您可以使用ListViewsetSelection功能滚动到列表中的特定项,如下所示...

listView.setSelection(2)

Or if you want it animated... 或者,如果您希望它具有动画效果...

listView.smoothScrollToPosition(2)

This answer is referenced from this answer . 该答案是从该答案中引用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM