【发布时间】:2012-04-26 08:46:21
【问题描述】:
我在这里疯了。我发誓我以前做过一千次这项工作,现在好像没有任何行为正常。我必须做一些愚蠢的事情。几天前,我遇到了列表视图项的背景问题,没有填充父项以延伸到列表视图项的高度。我终于放弃了,只是硬编码了一个高度来解决这个问题。现在我只是想设置整个活动的背景并让它填充它的父项,以便图像覆盖整个屏幕。此活动位于选项卡内。这是标签控制器的代码和我遇到问题的活动。
标签布局:
<?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 个小时我都无法自我回答,所以如果有人想将此作为答案,我会选择它作为正确答案。谢谢大家!
【问题讨论】:
-
你试过 android:scaleType="fitXY"
-
它必须与在标签内相关。我刚刚尝试了一个独立的活动,它工作正常。
标签: android android-layout tabs fill-parent