簡體   English   中英

android listView中的水平滾動

[英]Horizontal scroll in android listView

我想創建列表視圖,並具有水平和垂直方向上的功能。 該圖顯示了列表視圖中的行項目。 一切都應充當普通列表視圖-能夠垂直滾動。

除標題(Teszt Elk Nev)外,行中的其余數據也應水平排列。 (如您在圖像上看到的-第二行)當我水平滾動時,列表視圖中的所有行都應為scrool水平,因此所有行的scrool位置均相同。

在此處輸入圖片說明

我花了幾個小時嘗試解決它。 迄今為止最好的解決方案是將水平山cro酚僅排成一排。 我的行項目布局代碼。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/tvOne"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_marginRight="30dp"
        android:text="one" />

    <com.example.testproject.CustomHorScroll
        android:id="@+id/myHorScroll"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/myLay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="70dp"
                android:text="two" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="70dp"
                android:text="three" />

            <!-- rest items goes here --!>
        </LinearLayout>
    </com.example.testproject.CustomHorScroll>

</LinearLayout>

我想處理水平scrool運動並傳播到listview中的所有行,以設置horizo​​ntalscroolView.scrolBy(x,0)。 但是我不能使它起作用。 :/

另一個想法是跳過listview並使用滾動視圖和horizo​​ntalScroll創建自定義布局。

不幸的是,Android通常不支持滾動項中的滾動項。

最好的選擇可能是使用諸如ScrollView或Horizo​​ntalScrollView之類的東西,以及其中包含列表(或其他可滾動項)的LinearLayout: http : //developer.android.com/reference/android/widget/ScrollView.html

您可能想研究使用兩種方式的listview庫。

https://github.com/lucasr/twoway-view

暫無
暫無

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

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