2012-06-18 67 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

发现这是不可能的在列表视图中使用时,因为在这种情况下,父布局即线性布局总包的内容。

相关问题