如果我静态运行此代码,即只是创建一个示例程序,并做setcontentview它效果很好。imageview问题在相对布局
但是,如果我膨胀此视图并显示为列表视图项目。图像视图不会延伸。我需要在宽度为10dp的最左角出现一条黑色条,它应该像线一样填充视图。为每个项目。
另外请注意,如果我这样做android:layout_height =“?android:attr/listPreferredItemHeight”这样我的项目布局,它工作正常。但是项目内容没有完全显示,它会在特定的高度被截断。
我夸大我的看法是这样
convertView = mLayoutInflater.inflate(com.meganext.googletaskclient.R.layout.layout_list_item, parent, false);
这里是我的布局,我敢膨出的ListView
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp">
<ImageView
android:layout_width="10dp"
android:layout_height="fill_parent"
android:adjustViewBounds="false"
android:layout_marginTop="2dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:id="@+id/ID_task_item_priority"
android:src="@android:color/black"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Tasks TitleTasks TitleTasks TitleTasks Title Tasks TitleTasks TitleTasks Title"
android:id="@+id/ID_task_item_title"
android:layout_toRightOf="@+id/ID_task_item_priority"
android:singleLine="true"
android:ellipsize="end"
android:layout_marginRight="40dp"
android:textSize="25sp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ID_task_item_notes"
android:layout_below="@+id/ID_task_item_title"
android:layout_toRightOf="@+id/ID_task_item_priority"
android:maxLines="3"
android:ellipsize="end"
android:text="Task descriptionTask descriptionTask descriptionTask descriptionTask descriptionTask descriptionTask descriptionTask description"
android:layout_marginRight="4dp"
android:textSize="15sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/id_due_date"
android:layout_below="@+id/ID_task_item_notes"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:text="10-2-2014"
android:textSize="15sp"
/>
<CheckBox
android:id="@+id/ID_task_item_is_completed_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/ID_task_item_title"
android:layout_alignBottom="@+id/ID_task_item_title"
android:layout_alignParentRight="true"
android:focusable="false"
android:layout_marginRight="4dp" />
</RelativeLayout>
我的列表视图代码是
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="fill_parent"
android:adjustViewBounds="true"
android:layout_height="fill_parent"
android:id="@+id/home_activity">
</ListView>
</RelativeLayout>
输出。
宽度'10dp'你要的高度是'10dp'呢? – Raghunandan
不,我需要高度为fill_parent,那应该是列表项高度。 – Naruto
@Raghunandan,如果我这样做android:layout_height =“?android:attr/listPreferredItemHeight”这样的我的项目布局,它的工作正常。但是项目内容没有完全显示,它会在特定的高度被截断。 – Naruto