1

我有一个简单的 ListView 显示一些内容。有真实的内容视图@+id/conetnt和一个视图@+id/service_disabled只是为了显示一些花哨的背景,以防项目被禁用。禁用视图的背景应绘制在内容之上。这就是不为内容视图使用背景状态选择器的原因。

内容视图的高度因项目而异。我基本上希望禁用的视图高度与内容视图的高度相同。

但无论我尝试什么,在 API<11 上,禁用的视图高度match_parent都会被忽略。禁用的视图只有很小的高度。在 API>=11 上一切都很好。

我的列表项布局:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

    <LinearLayout android:id="@+id/content"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:gravity="center_vertical"
                  android:orientation="horizontal"
                  android:padding="@dimen/service_item_padding">

        <!-- views... -->
    </LinearLayout>

    <View android:id="@+id/service_disabled"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@drawable/bg_disabled_service_repeat"/>

</FrameLayout>

任何想法如何在 API<11 上解决这个问题?

顺便说一句:minSdk=8,targetSdk=18

它在运行 android-17 的 N4 和 tf101 上运行良好。它在我运行 android-10 的 HTC G2 上坏了。

4

2 回答 2

0

想一想:一个项目的父ListView项是什么,它的高度是多少?使列表视图项等于其父高度将使整个列表视图无用。

您可能希望列表行布局的高度为wrap_content.

于 2013-08-16T08:46:42.267 回答
-1

您是专门为旧 API 版本编译的吗?您测试了哪些 API 版本?

它可以像不正确的命名一样简单。MATCH_PARENT 是在 API 8 及更高版本上使用的名称,但如果您使用的是 API 7 或更早版本(Android 2.1 Eclair 或更早版本),则应改用常量 FILL_PARENT。

于 2013-08-16T08:13:25.583 回答