2012-06-18 72 views
4

我想用右側的陰影繪製我的整個列表項目。Match_parent高度內部佈局與wrap_content高度

問題是我的包裝drawable的佈局沒有一個不變的高度。我厭倦了設置我的繪製對齊父頂部和對齊父底部,但它仍然不會伸展它的父級佈局的整個高度。

看ATT右邊的陰影(我提供一分鐘height屬性使其可見,第四列表項比min查看做大,影子不舒展)

enter image description here

來源:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <include layout="@layout/list_item_header" /> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/img_news_thumb" 
      android:layout_width="@dimen/listview_one_row" 
      android:layout_height="@dimen/listview_one_row" 
      android:scaleType="centerCrop" 
      android:src="@drawable/default_news_thumb" /> 

     <TextView 
      android:id="@+id/txt_news_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_alignWithParentIfMissing="true" 
      android:layout_marginLeft="@dimen/space_m" 
      android:layout_marginTop="@dimen/space_s" 
      android:layout_toRightOf="@+id/img_news_thumb" 
      android:ellipsize="marquee" 
      android:paddingRight="@dimen/space_m" 
      android:singleLine="false" 
      android:text="Title" 
      android:textSize="14sp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/txt_news_date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignWithParentIfMissing="true" 
      android:layout_below="@+id/txt_news_title" 
      android:layout_marginBottom="0dp" 
      android:layout_marginLeft="@dimen/space_m" 
      android:layout_marginTop="@dimen/space_s" 
      android:layout_toRightOf="@+id/img_news_thumb" 
      android:ellipsize="end" 
      android:paddingRight="@dimen/space_m" 
      android:singleLine="true" 
      android:text="Date" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/font_light" /> 

     **<ImageView 
      android:id="@+id/img_news_list_shadow" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_alignParentBottom="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignTop="@+id/img_news_thumb" 
      android:minHeight="@dimen/listview_one_row" 
      android:scaleType="fitXY" 
      android:src="@drawable/list_shadow_r" />** 

     <ImageView 
      android:id="@+id/img_selected_arrow" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_centerVertical="true" 
      android:scaleType="fitXY" 
      android:src="@drawable/list_item_arrow" 
      android:visibility="gone" /> 
    </RelativeLayout> 

    <include layout="@layout/list_item_devider" /> 

</LinearLayout> 
+0

你使用普通的PNG的陰影或者你使用伸縮niner PNG格式? http://developer.android.com/guide/developing/tools/draw9patch.html –

+0

我使用niner pngs – Richard

+0

嘗試android:layout_height =「?android:attr/listPreferredItemHeight」爲包含佈局的列表項 –

回答

0

由於最近的調查,我發現答案比這要簡單得多。

當充氣的佈局,我們應該用這樣的:

View rowView = inflater.inflate(R.layout.row_layout, parent, false); 

取而代之的是常用的錯誤:

View rowView = inflater.inflate(R.layout.row_layout, null); 
1

發現這是不可能的在列表視圖中使用時,因爲在這種情況下,父佈局即線性佈局總包的內容。

相關問題