0

我在这里疯了。我发誓我以前做过一千次这项工作,现在好像没有任何行为正常。我必须做一些愚蠢的事情。几天前,我遇到了列表视图项的背景问题,没有填充父项以延伸到列表视图项的高度。我终于放弃了,只是硬编码了一个高度来解决这个问题。现在我只是想设置整个活动的背景并让它填充它的父项,以便图像覆盖整个屏幕。此活动位于选项卡内。这是选项卡控制器的代码和我遇到问题的活动。

标签布局:

<?xml version="1.0" encoding="utf-8"?>
<TabHost 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

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

    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

        <FrameLayout
            android:id="@android:id/tabcontent"            
            android:layout_width="fill_parent"            
            android:layout_height="fill_parent">

        </FrameLayout>
</LinearLayout>
</TabHost>

麻烦的活动:

<?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="fill_parent"
android:background="@drawable/background">

<RelativeLayout
    android:id="@+id/localHeader"
    android:layout_width="fill_parent"
    android:layout_height="50dip"
    android:background="@drawable/header2">

    <Button
        android:id="@+id/changeCityButton"
        android:layout_width="80dip"
        android:layout_height="30dip"
        android:layout_marginRight="10dip"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:onClick="buttonChangeOnClickListener"
        android:text="Change"
        android:textColor="#FFFFFF"
        android:background="@drawable/local_deal_redeem_button" />

    <TextView
        android:id="@+id/cityName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dip"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/changeCityButton"
        android:textSize="20dip"
        android:textColor="#FFFFFF"
        android:textStyle="bold"
        android:shadowColor="#FF000000"
        android:shadowDx="1"
        android:shadowDy="1"
        android:shadowRadius="1"/>

</RelativeLayout>

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/localHeader"
    android:fastScrollEnabled="true"
    android:cacheColorHint="#00000000"
    android:divider="@null"
    android:dividerHeight="0px"/>

</RelativeLayout>

这个问题似乎只发生在新的 Bionic 上。“@drawable/background”只会拉伸到列表视图的长度。如果列表视图中没有项目,它将不会显示任何内容。我什至尝试将其从布局中剥离出来并使其只是一个图像视图,但这也不起作用。就好像我在某处缺少一个 wrap_content 标记。通常我只会说这是仿生的问题,但看到我如何在 ListView 背景中遇到这些问题,我想我在某个地方搞砸了。请帮忙!!

同样在我的清单中:

<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:resizeable="true" android:anyDensity="true"></supports-screens>

但是我已经尝试删除它,无论我在该行中输入什么值,它都不会在我的应用程序中执行任何操作。

编辑:我刚刚意识到,如果我将图像放入“fill_parent”滚动视图,背景将相应地拉伸。但是,由于屏幕包含一个 ListView,我不能走这条路。这里有些古怪。

编辑 2:我刚刚撕掉了列表视图,它工作得很好。它在某种程度上与列表视图有关。

编辑 3:我刚刚通过将 ListView 高度设置为“wrap_content”解决了这个问题。我不知道为什么“fill_parent”会在此设备上导致此行为,但它已修复,所以现在一切都很好。再过 6 个小时我都无法自我回答,所以如果有人想将此作为答案,我会选择它为正确的。感谢大家!

4

3 回答 3

1

我通过将 ListView 高度设置为 wrap_content 来解决它。我不知道为什么 fill_parent 会在这部手机上导致这种行为,但它现在可以正常运行,所以一切都很好。感谢大家!

于 2011-10-07T01:02:16.973 回答
0

使用片段尝试此逻辑,因为选项卡现在已弃用。这是我的观点,一旦尝试,它也可能是错误的。

于 2011-10-06T17:27:52.913 回答
0

我只是在研究这个问题,发现了这个:

http://community.developer.motorola.com/t5/MOTODEV-Blog/Why-Does-My-ListView-Look-Different/ba-p/17462

基本上,Bionic 上的默认主题在 ListView 上设置了 android:overScrollFooter。将其设置为 @null 将提供其他设备表现出的行为。

于 2012-04-26T00:46:21.490 回答