簡體   English   中英

Listview根據圖像按鈕滾動

[英]Listview scrolling according to the image button

我有一個listview。我禁用了listview中的滾動。 我在列表視圖的開始和結束處有2個圖像按鈕。 現在我想要的是1)通過單擊這些按鈕,列表視圖應相應地向上/向下移動,並且每次單擊按鈕時它都應向上/向下移動一行。 2)我不知道如何在列表視圖中添加圖像按鈕。 我試圖添加頁眉和頁腳,但我不能。 我的任何布局都必須像 ()

作為一個新手,可以幫助我實現上述兩個目標。 我基於鏈接創建了列表視圖。 提前致謝

按照@Terril Thomas的建議,制作RelativeLayout並將listView和兩個ImageView放入注釋中。 另外,在加載listView時,您可以對這些按鈕執行操作,例如

listView.smoothScrollToPosition("row_no");

為了平滑滾動,或者您也可以像

listView.setSelection("row_no");

您只需要執行類似的操作,如果單擊底部圖像,則需要增加 數字並調用listView.smoothScrollToPosition("incremented number"); 還要檢查條件if("incremented number" < listView.size())然后只需要滾動到該位置即可。 對於與此相反的頂部圖像,即遞減數字並檢查if("decremented number" > 0) ,如果為true,則滾動到遞減數字!

對於用戶界面,您可以創建一個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頁眉和頁腳的更多信息,請檢查: 此鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM