简体   繁体   English

如何在水平 ListView 中制作垂直滚动行

[英]How to make vertically Scrollable row in a horizontal ListView

I want to implement Android Horizontal list view with Vertically scrollable content in each row.我想实现 Android 水平列表视图,每行都包含可垂直滚动的内容。 Please help me out.请帮帮我。

Depends upon how you are planning to make each row, in XML or programatically.取决于您打算如何在 XML 中或以编程方式制作每一行。
Either way you just need to put your View or Layout for row in a ScrollView and fix a height for it.无论哪种方式,您只需要将行的ViewLayout放在ScrollView中并为其固定高度。

Horizontal listview inside vertical listview (and scrolling multiple listviews together) 垂直列表视图内的水平列表视图(以及一起滚动多个列表视图)

A horizontal list view can contain each item inside a vertical scroll view.水平列表视图可以包含垂直滚动视图中的每个项目。

You have to create the Custom list view.您必须创建自定义列表视图。 Below is the Code: You have to put the Listview inside the Horizontal Scroll View:以下是代码:您必须将 Listview 放在水平滚动视图中:

<HorizontalScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/imageViewseparatorListview"
            android:id="@+id/hor">

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/relcoll"
                android:background="@drawable/wallpapertheme">

                <TextView
                    style="@style/ListViewHeaderTheme"
                    android:id="@+id/textviewoutletname"
                    android:text="@string/textviewoutletname"
                    android:layout_width="180dip"
                    android:background="@drawable/listview_heading_background" />



                <ImageView
                    style="@style/ListViewHeaderSeperator"
                    android:id="@+id/imageViewseparator1"
                    android:layout_toRightOf="@id/textviewoutletname" />

                <TextView
                    style="@style/ListViewHeaderTheme"
                    android:id="@+id/textviewcashamount"
                    android:text="@string/textviewcashamount"
                    android:layout_width="90dip"
                    android:layout_toRightOf="@id/imageViewseparator1"
                    android:background="@drawable/listview_heading_background" />

                <ImageView
                    style="@style/ListViewHeaderSeperator"
                    android:id="@+id/CollectionBarSeparator1"
                    android:layout_toRightOf="@id/textviewcashamount" />

                <TextView
                    style="@style/ListViewHeaderTheme"
                    android:id="@+id/textviewchequeamount"
                    android:text="@string/textviewchequeamount"
                    android:layout_width="90dip"
                    android:layout_toRightOf="@id/CollectionBarSeparator1"
                    android:background="@drawable/listview_heading_background" />

                <ImageView
                    style="@style/ListViewHeaderSeperator"
                    android:id="@+id/CollectionBarSeparator2"
                    android:layout_toRightOf="@id/textviewchequeamount" />

                <TextView
                    style="@style/ListViewHeaderTheme"
                    android:id="@+id/textviewosamount"
                    android:text="@string/textviewosamount"
                    android:layout_width="105dip"
                    android:layout_toRightOf="@id/CollectionBarSeparator2"
                    android:background="@drawable/listview_heading_background" />



                <ListView
                    style="@style/ListViewTheme"
                    android:id="@+id/listviewcollection"
                    android:layout_below="@id/textviewosamount"></ListView>

            </RelativeLayout>


        </HorizontalScrollView>

Listview.xml列表视图.xml

**Second.XML**
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    style="@style/ListViewTextViewParent">

    <TextView
        style="@style/ListViewTextView"
        android:id="@+id/textviewoutletname"
        android:text="Mayur"
        android:layout_width="180dip" />

    <ImageView
        style="@style/ListViewTextSeperatorForAll"
        android:id="@+id/imageViewseparator1" />

    <TextView
        style="@style/ListViewTextView"
        android:id="@+id/textviewcashamount"
        android:text="2001"
        android:gravity="right"
        android:layout_width="90dip" />

    <ImageView
        style="@style/ListViewTextSeperatorForAll"
        android:id="@+id/imageViewseparator1" />

    <TextView
        style="@style/ListViewTextView"
        android:id="@+id/textviewchequeamount"
        android:text="3000"
        android:layout_width="90dip"
        android:gravity="right" />

    <ImageView
        style="@style/ListViewTextSeperatorForAll"
        android:id="@+id/imageViewseparator1" />

    <TextView
        style="@style/ListViewTextView"
        android:id="@+id/textviewosamount"
        android:text="5000"
        android:gravity="right"
        android:layout_width="100dip" />


</LinearLayout>

Now extend class by the Base Adapter In your activity And Inflate second.xml file.现在通过基本适配器在您的活动中扩展 class 并膨胀 second.xml 文件。

And If You want you can take reference of below link also:如果您愿意,也可以参考以下链接:

adding ListView children to a HorizontalScrollView 将 ListView 子级添加到 HorizontalScrollView

create one vertical scroll view创建一个垂直滚动视图

add that view to your horizontal scroll view将该视图添加到水平滚动视图

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

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