【问题标题】:Android - Prevent ListView from shrinking child viewsAndroid - 防止 ListView 缩小子视图
【发布时间】:2010-10-19 22:31:03
【问题描述】:

Android ListView 小部件 (2.2) 有一个默认行为,即在 ListView 滚动时缩小所有子视图。

我想禁用此行为并且不缩小子视图,以便它们始终保持相同的大小 -- 我该怎么做?

【问题讨论】:

  • 你的布局是什么样的?
  • 我正在使用 FILL_PARENT 以编程方式构建 ListView,这些集合是:setPadding(5, 5, 5, 5); setCacheColorHint(0); setBackgroundColor(Color.argb(200, 0, 0, 0));
  • “Android ListView 小部件 (2.2) 有一个默认行为,即在 ListView 滚动时缩小所有子视图。” ——有代码吗?我没有看到这种行为。
  • 我的应用在除 froyo 之外的所有操作系统中都能完美运行,滚动时列表视图中的某些元素会缩小

标签: android listview scroll


【解决方案1】:

我正在使用从以下位置膨胀的视图以编程方式填充 ListView:

< RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" android:layout_width="fill_parent">

    <ImageView android:id="@+id/actionitem_image"
        android:layout_centerVertical="true" android:layout_width="40dp"
        android:layout_height="40dp" android:scaleType="center" />

    <TextView android:layout_height="wrap_content" android:id="@+id/actionitem_title"
        android:layout_toRightOf="@+id/actionitem_image" android:textColor="@color/white"
        android:text="TITLE" android:textSize="14dp" android:layout_width="fill_parent" />
    <TextView android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/actionitem_image" android:layout_below="@+id/actionitem_title"
        android:id="@+id/actionitem_subtitle" android:text="Sub Title"
        android:textSize="12dp" android:layout_width="fill_parent" />
    <TextView android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/actionitem_image" android:layout_below="@+id/actionitem_subtitle"
        android:id="@+id/actionitem_infoa" android:textSize="10dp"
        android:layout_width="fill_parent" />
    <TextView android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/actionitem_image" android:layout_below="@+id/actionitem_infoa"
        android:id="@+id/actionitem_infob" android:textSize="10dp"
        android:layout_width="fill_parent" />
    <TextView android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/actionitem_image" android:id="@+id/actionitem_infoc"
        android:layout_below="@+id/actionitem_infob" android:textSize="10dp"
        android:layout_width="fill_parent" />
    <TextView android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/actionitem_image" android:id="@+id/actionitem_infod"
        android:layout_below="@+id/actionitem_infoc" android:textSize="10dp"
        android:layout_width="fill_parent" />
</RelativeLayout>

每当列表滚动时,都会出现一些奇怪的行为,其中一些视图会缩小。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多