0

我有自定义列表视图布局。列表中的项目将是 5 个或更多。如果不止说,列表中有 5-10 个项目,它看起来不错。

但是如果说只有 5 个项目,那么在高度较大的设备上,列表下方会出现空白。这看起来不太好。

以下是我的列表行布局 -

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#FFF"
    android:orientation="horizontal"
    android:padding="5dip" >

    <TextView
        android:id="@+id/txt_update_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:paddingLeft="10sp"
        android:text="title"
        android:textColor="#b73a3e"
        android:textStyle="bold"
        android:typeface="normal" />

    <TextView
        android:id="@+id/txt_update_excerpt"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/txt_update_title"
        android:layout_marginTop="1dip"
        android:focusable="false"
        android:paddingLeft="10sp"
        android:paddingRight="10dp"
        android:text="text"
        android:textColor="#343434"
        android:textSize="15dip" />

    <TextView
        android:id="@+id/txt_uid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="20dip"
        android:layout_toRightOf="@+id/txt_update_title"
        android:focusable="false"
        android:text="some" />

    <ImageView
        android:id="@+id/arrow"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_alignBottom="@+id/txt_uid"
        android:layout_alignRight="@+id/txt_update_excerpt"
        android:layout_centerInParent="true"
        android:scaleType="centerInside"
        android:paddingRight="5dp"
        android:src="@drawable/arrow" />

</RelativeLayout>

和列表视图 -

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="10dp" >

        <TextView
            android:id="@+id/tag_line"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/tagline"
            android:textColor="#fff" />

        <ListView
            android:id="@+id/list_updates"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:cacheColorHint="#0000"
            android:divider="#00000000"
            android:dividerHeight="0px"
            android:overScrollMode="never" >
        </ListView>
</LinearLayout>

我想要的是,如果设备的高度更大,那么我希望列表通过缩放每行的高度来获取完整的高度,以便它应该显示所有项目而无需滚动。如果项目更多,则应出现滚动。我该如何设置?


更新

我可以选择一个解决方案,在该解决方案中,我会检查之前列表中有多少项目,如果它们少于 5-6,我会选择一个不同的布局,包括 LinearLayout 或会填满的东西空白处。但我无法弄清楚我需要为此类选择的结构LinearLayout。我应该选择一个下面的 5-6 LinearLayout 还是选择一个迭代?

4

1 回答 1

1

好吧,在我看来,如果我需要实现这样的功能,我会这样做:

  • 检查是否存在您不想要的空白(blankHeight=(ListViewHeight-count*rowHeight)>0)
  • heightToPlus = 空白高度/计数
  • 然后您可以将每行的高度设置为 rowHeight+heightToPlus

每个高度都可以通过 getHeight 获取,也可以通过 setHeight 设置,它们是视图的方法。
所以我认为实施起来并不难......

于 2013-08-31T16:02:51.457 回答