【问题标题】:Match_parent height inside layout with wrap_content heightMatch_parent 布局内的高度与 wrap_content 高度
【发布时间】:2013-07-25 19:53:50
【问题描述】:

我正在尝试用右侧的可绘制阴影覆盖整个列表项。

问题是我包裹可绘制对象的布局没有恒定的高度。我厌倦了将我的可绘制对象设置为对齐父顶部和对齐父底部,但它仍然没有拉伸其父布局的整个高度。

看右边的阴影(我提供了一个最小高度属性使其可见,第四个列表项大于最小视图,并且阴影没有拉伸)

来源:

<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>

【问题讨论】:

标签: android android-layout


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    由于最近的调查,我发现答案比这简单得多。

    膨胀布局时,我们应该使用这个:

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

    而不是常用的错误:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-09
      相关资源
      最近更新 更多