Android中水平滚动视图内的宽垂直ListView

时间:2014-11-05 09:57:42

标签: android listview scroll xamarin

我的Android应用中有一个垂直列表视图。

它的样式看起来像一个带有列的表,即每个listview项模板在水平线性布局中有多个textview。每个textview都有一个宽度,例如12个文本视图,每个200dp意味着listview的宽度需要为2400dp。

这个listview需要垂直滚动,因为这是listview的内置功能。但是,由于listview的宽度很大,我还需要它也可以水平滚动(因为我不想在textviews上使用权重并挤压以适应屏幕宽度)。

我想把listview放在水平滚动视图中。然后在listview上设置宽度为2400dp,将水平scollview宽度设置为match_parent。

但是,scrollview似乎没有扩展到足以显示listview的完整宽度。它水平滚动但不够。这种方法我哪里错了?

在页面中:

<HorizontalScrollView
      android:layout_height="match_parent"
      android:layout_width="match_parent">
      <ListView
        android:layout_height="match_parent"
        android:layout_width="2400dp"/>
    </HorizontalScrollView>

ListView项目

<LinearLayout
      android:orientation="horizontal"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">
      <TextView
        android:text="Long text here..."
        android:layout_width="200dp"
        android:layout_height="match_parent"/>
      <TextView
        android:text="Long text here..."
        android:layout_width="200dp"
        android:layout_height="match_parent"/>
      <TextView
        android:text="Long text here..."
        android:layout_width="200dp"
        android:layout_height="match_parent"/>
      <TextView
        android:text="Long text here..."
        android:layout_width="200dp"
        android:layout_height="match_parent"/>
      <TextView
        android:text="Long text here..."
        android:layout_width="200dp"
        android:layout_height="match_parent"/>
      <TextView
        android:text="Long text here..."
        android:layout_width="200dp"
        android:layout_height="match_parent"/>
      <TextView
        android:text="Long text here..."
        android:layout_width="200dp"
        android:layout_height="match_parent"/>
      <TextView
        android:text="Long text here..."
        android:layout_width="200dp"
        android:layout_height="match_parent"/>
      <TextView
        android:text="Long text here..."
        android:layout_width="200dp"
        android:layout_height="match_parent"/>
      <TextView
        android:text="Long text here..."
        android:layout_width="200dp"
        android:layout_height="match_parent"/>
      <TextView
        android:text="Long text here..."
        android:layout_width="200dp"
        android:layout_height="match_parent"/>
      <TextView
        android:text="Long text here..."
        android:layout_width="200dp"
        android:layout_height="match_parent"/>
    </LinearLayout>

1 个答案:

答案 0 :(得分:0)

TextViews内部加起来恰好2400dp,你给listview正好2400dp的宽度,但我认为listview本身需要几个dp例如小滚动条滚动项目垂直我会认为这是像素你缺少

相关问题