我有一个列表视图。我禁用了列表视图中的滚动。我在列表视图的开头和结尾有 2 个图像按钮。现在我想要的是 1)通过单击这些按钮,列表视图应该相应地向上/向下移动,并且它应该在每次按钮单击时向上/向下移动一行。2) 我不知道如何在列表视图中添加图像按钮。我尝试添加页眉和页脚,但我不能。我的任何布局都需要像
作为一个新手帮助我实现上述两个。我基于此链接创建了我的列表视图。提前致谢
按照@Terril Thomas 在评论中的建议,制作RelativeLayout
并放置listView
两个s。ImageView
此外,当加载 listView 时,您可以对这些按钮执行操作,例如
listView.smoothScrollToPosition("row_no");
为了平滑滚动,或者您也可以滚动
listView.setSelection("row_no");
你只需要做类似的事情,如果你点击底部的图片,那么你需要增加数字并调用listView.smoothScrollToPosition("incremented number");
检查条件if("incremented number" < listView.size())
然后你只需要滚动到那个位置。对于与此相反的顶部图像,即减少数字并检查if("decremented number" > 0)
,如果为真,则滚动到减少的数字!
对于 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
请查看:此链接