【问题标题】:Listview scrolling according to the image buttonListview根据图像按钮滚动
【发布时间】:2018-04-03 10:10:58
【问题描述】:

我有一个列表视图。我禁用了列表视图中的滚动。我在列表视图的开头和结尾有 2 个图像按钮。现在我想要的是 1)通过单击这些按钮,列表视图应相应地向上/向下移动,并且在每次单击按钮时应向上/向下移动一行。 2) 我不知道如何在列表视图中添加图像按钮。我尝试添加页眉和页脚,但我不能。 我的任何布局都需要像

作为一个新手帮助我实现上述两个。我基于this 链接创建了我的列表视图。 提前致谢

【问题讨论】:

  • 相反,您应该使用匹配父级的图像视图,分别使用 alignparentTop 和 alignparentbottom。然后在 betwwen 中添加列表视图。
  • 你能用小例子解释一下吗

标签: android listview


【解决方案1】:

按照@Terril Thomas 在评论中的建议,制作RelativeLayout 并放入listView 和两个ImageViews。此外,当加载 listView 时,您可以对这些按钮执行操作,例如

listView.smoothScrollToPosition("row_no");

为了平滑滚动,您也可以像滚动一样滚动

listView.setSelection("row_no");

你只需要这样做,如果你点击底部图片,那么你需要增加 数字并调用listView.smoothScrollToPosition("incremented number");还要检查条件if("incremented number" < listView.size()) 然后只有你必须滚动到那个位置。对于与此相反的顶部图像,即减少 number 并检查 if("decremented number" > 0),如果为 true,则滚动到减少的数字!

对于 UI,您可以创建一个 RelativeLayout,然后您可以放置​​:

<ImageButton 
    android:id="@+id/scrollUp"
    android:layout_alignParentTop="true"
    android:clickable="true"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="@android:color/holo_blue_dark"/>

<ListView 
    android:layout_margin="5dp"
    android:layout_below="@id/scrollUp"
    android:layout_above="@+id/scrollDown"
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</ListView>

<ImageButton 
    android:id="@+id/scrollDown"
    android:layout_alignParentBottom="true"
    android:clickable="true"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="@android:color/holo_blue_dark"/>

这将导致:

希望你明白我的意思。

有关ListView 的页眉和页脚的更多信息,请查看:this link

【讨论】:

  • 感谢您的回复。我需要我的图像视图在列表视图上,就像在页眉和页脚中添加图像视图一样。但我不知道该怎么做。这里的数字表示哪一个。能不能详细解释一下。
  • 请查看更新后的答案。我还提到了“那个数字”=“增加/减少的数字”,也参考一下
  • 我解决了 img btn 问题,正在尝试滚动行。一旦我得到答案,我会让你知道。你能在检查条件后告诉我如何向上/向下滚动位置
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-30
  • 2011-01-23
  • 2018-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多