我目前正在对项目进行小型更新,并且在列表视图中遇到了Relative_Layout和fill_parent的问题。我试图在每一行的两部分之间插入一个分隔符,就像默认拨号程序的通话记录中的分隔符。我查看了Android源代码,看看他们是如何做到的,但是我在复制他们的解决方案时遇到了一个问题。Android的RelativeLayout fill_parent意外的行为在不同的行高的ListView中
要启动,这是我行的产品布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dip"
android:layout_height="fill_parent"
android:maxHeight="64dip"
android:minHeight="?android:attr/listPreferredItemHeight">
<ImageView android:id="@+id/infoimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:src="@drawable/info_icon_big"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
<View android:id="@+id/divider"
android:background="@drawable/divider_vertical_dark"
android:layout_marginLeft="11dip"
android:layout_toLeftOf="@+id/infoimage"
android:layout_width="1px"
android:layout_height="fill_parent"
android:layout_marginTop="5dip"
android:layout_marginBottom="5dip"
android:layout_marginRight="4dip"/>
<TextView android:id="@+id/TextView01"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/ImageView01"
android:layout_toLeftOf="@+id/divider"
android:gravity="left|center_vertical"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"/>
<ImageView android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="@drawable/bborder"
android:layout_centerVertical="true"/>
</RelativeLayout>
我现在面临的问题是,每一行都有不同高度(ImageView01)的缩略图。如果将RelativeLayout的layout_height属性设置为fill_parent,则分隔线不会垂直缩放以填充行(它只是1px点)。如果我将layout_height设置为“?android:attr/listPreferredItemHeight”,则分隔符会填充行,但缩略图会缩小。我已经在适配器的getView()方法中进行了一些调试,并且一旦行具有合适的高度,分区的高度似乎就不会被正确设置。
这里是getView()方法的一部分:
public View getView(int position, View view, ViewGroup parent) {
if (view == null) {
view = inflater.inflate(R.layout.tag_list_item, parent, false);
}
该方法的其余部分简单地设置该行的相应的文本和图像。
另外,我创建将适配器的构造充气对象:inflater = LayoutInflater.from(context);
我缺少的东西必不可少的?或者fill_parent只是不适用于动态高度?
感谢您的回答!但是,分隔线仍然不会垂直填充该行。我不确定这种行为是否是一个错误,或者是否有其他缺失的东西。任何其他想法? – 2010-05-04 06:03:29