【问题标题】:How to use horizontal scroll in listview?如何在列表视图中使用水平滚动?
【发布时间】:2013-01-18 04:36:54
【问题描述】:

我正在开发一个安卓应用程序。创建了Layout,其中包含不同的布局。

其中还有一个listview。我将 custom adapter 用于 listview 。我想在listview 中显示水平滚动。但是当我在其中应用水平滚动时,它会显示每个项目。但不是最后。

请建议我如何应用它。

代码如下:-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg" >

<include
    android:id="@+id/mainScreenHeader"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    layout="@layout/main_screen_header" />

<include
    android:id="@+id/mainScreenListHeader"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/mainScreenHeader"
    layout="@layout/main_screen_list_header" >
</include>

<ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="270dp"
    android:layout_below="@+id/mainScreenListHeader"
    android:cacheColorHint="#00000000"
    android:drawSelectorOnTop="false" />

<include
    android:id="@+id/mainScreenFilterClient"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/list"
    android:layout_marginTop="10dp"
    layout="@layout/main_screen_filter_client" >
</include>

<include
    android:id="@+id/footer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/mainScreenFilterClient"
    android:layout_marginTop="10dp"
    layout="@layout/footer" >
</include>

【问题讨论】:

    标签: android listview horizontalscrollview


    【解决方案1】:

    我正在使用这个库,你可以试试这个:

    https://github.com/sephiroth74/HorizontalVariableListView

    【讨论】:

      【解决方案2】:

      dev-smart 上有一篇关于这个的优秀文章

      Horizontal Scroll in ListView

      检查一下

      【讨论】:

      【解决方案3】:

      这会对你有所帮助..

      <com.devsmart.android.ui.horizontiallistview 
      android:id="@+id/listview" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"
      android:background="#ddd"> 
      

      android:orientation="horizontal"
      

      【讨论】:

      • android:orientation="horizo​​n..." 这应该在哪里使用。
      【解决方案4】:

      xml 文件中声明HorizontalListView

          HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:fillViewport="true" 
      

      【讨论】:

      • 我正在添加水平滚动,但它出现在列表视图的每一行中的每个列表项 .scroll 中。
      【解决方案5】:

      您应该在适配器中通过声明几种类型的视图来做到这一点。然后对于每个元素,您返回第一种类型的视图和最后一秒,这将是一个 Horizo​​ntalScrollView。:

      @Override
      public int getViewTypeCount() {
          return 2;
      }
      
      @Override
      public int getItemViewType(int position) {
          return isLastPositionInList ? 1 : 0;
      }
      

      然后

      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
      
          final int itemViewType = getItemViewType(position);
      
          switch(itemViewType) {
              case 0:
                 // prepare here your usual view
              case 1:
                 // prepare here the horizontal view
      

      【讨论】:

        猜你喜欢
        • 2019-05-17
        • 1970-01-01
        • 2014-05-12
        • 1970-01-01
        • 1970-01-01
        • 2013-01-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多