如果我靜態運行此代碼,即只是創建一個示例程序,並做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