【发布时间】: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<String>(this,android.R.layout.simple_list_item_1,....))的参数,它设置您的列表视图项目的样式和/或您在自定义适配器的 getView() 中设置您的项目样式,并将您的 item_row 描述为 xml,然后在 getView() 中再次膨胀. -
我想将项目设置为带有填充的列表。该列表有一个适配器。
标签: android xml listview height