我正在进行一个项目的小更新,我在列表视图中遇到了Relative_Layout和fill_parent的问题.我试图在每行的两个部分之间插入一个分隔符,就像默认拨号器的调用日志中的分隔符一样.我检查了Android源代码,看看他们是如何做到的,但是在复制他们的解决方案时遇到了问题.
首先,这是我的行项目布局:
<?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>
Run Code Online (Sandbox Code Playgroud)
我面临的问题是每行都有一个不同高度的缩略图(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);
}
Run Code Online (Sandbox Code Playgroud)
该方法的其余部分只是为行设置适当的文本和图像.
另外,我在适配器的构造函数中创建了inflater对象: inflater = LayoutInflater.from(context);
我错过了必不可少的东西吗 或者fill_parent不适用于动态高度?