【问题标题】:Set listview items with a specific height设置具有特定高度的列表视图项
【发布时间】:2012-08-05 15:09:05
【问题描述】:

我想调整列表视图中具有特定高度的项目。

我做的适配器:?android:attr/listPreferredItemHeight,当listview的高度为fill_parent时效果很好。

<TextView
    android:id="@+id/FirstText"
    android:layout_width="wrap_content" 
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:layout_weight="1"
    android:gravity="center_vertical"
    android:paddingBottom="10dip"
    android:paddingLeft="6dip"
    android:paddingTop="12dip"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:textSize="18dip"
    android:textColor="#000000" />

<ListView
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:cacheColorHint="#ffffff"
    android:divider="#4436f2"
    android:dividerHeight="1px"
    android:scrollbars="none"
    android:fadingEdge="none"/>

但是当列表视图的高度是特定大小时,不适合项目。

<ListView
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="200sp"
    android:background="#ffffff"
    android:cacheColorHint="#ffffff"
    android:divider="#4436f2"
    android:dividerHeight="1px"
    android:scrollbars="none"
    android:fadingEdge="none"/>

如何使用特定列表视图调整项目的高度?

【问题讨论】:

  • 您如何为列表视图设置适配器?你在 setAdapter() 方法中使用了哪些参数?
  • 您的向上 n 向下按钮不在列表中?
  • 所以你想调整项目,使它们都适合列表视图的给定高度?
  • 我假设这些是列表的页眉和页脚并且是静态的。基本上有 ...setAdapter(new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1,....)) 的参数,它设置您的列表视图项目的样式和/或您在自定义适配器的 getView() 中设置您的项目样式,并将您的 item_row 描述为 xml,然后在 getView() 中再次膨胀.
  • 我想将项目设置为带有填充的列表。该列表有一个适配器。

标签: android xml listview height


【解决方案1】:

更好地使用自定义适配器,你可以做任何你想做的事

【讨论】:

  • 你能补充更多细节吗?因为这并不能解释太多。
  • 我们希望您将信息放在帖子中,这样如果链接失效,信息仍然可用。
  • 我实际上对这个特定领域一无所知,但无论如何这些规则都适用。
  • 我正在使用带有适配器的列表视图,但我无法将列表视图项目设置为用作填充
猜你喜欢
  • 1970-01-01
  • 2014-09-24
  • 1970-01-01
  • 2012-11-04
  • 2019-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-24
相关资源
最近更新 更多