简体   繁体   English

视图的高度与父级RelativeLayout的高度不同

[英]View not taking the same height as parent RelativeLayout

I'm trying to achieve the layout on the right of the image below. 我正在尝试实现下图右侧的布局。 What I am currently getting is on the left. 我现在得到的是在左边。

屏幕截图

Here is my layout: 这是我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >

    <ImageView
        android:id="@+id/garment_grid_item_image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:background="@drawable/gridview_image_placeholder"
        android:contentDescription="@string/blank"
        android:scaleType="centerCrop"
        />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/garment_grid_item_on_loan"
        android:src="@drawable/icon_borrowed"
        android:contentDescription="@string/blank"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:visibility="gone"
        />

    <View
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:background="@drawable/item_border"
        />

</RelativeLayout>

@drawable/item_border (lime green is just to highlight the transparent areas): @drawable/item_border (石灰绿色只是为了突出透明区域):

9个补丁可绘制

The RelativeLayout is used as an item template for a GridView . RelativeLayout用作GridView的项目模板。 garment_grid_item_image is being populated in code. garment_grid_item_image正在代码中填充。 garment_grid_item_on_loan is the purple triangle in the top right whose visibility is controlled in code. garment_grid_item_on_loangarment_grid_item_on_loan的紫色三角形,其可见性由代码控制。

The View at the bottom uses a 9 patch and it is the one I'm having trouble with. 底部的View使用9补丁,这是我遇到的问题。 I want it to be as tall as the parent RelativeLayout but neither match_parent or fill_parent work. 我希望它和父级RelativeLayout一样高,但是match_parentfill_parent都不能工作。 What can I do to get it to work? 我该怎么做才能使其正常工作?

I've just tried your layout with some similar images and it works fine when set as the root element in an Activity. 我刚刚尝试过使用一些相似的图像进行布局,并且在Activity中设置为根元素时,效果很好。

It could be to do with your RelativeLayout having wrap_content as its size, with the child Views not specifying a size to wrap. 这可能与您的RelativeLayout具有wrap_content的大小有关,而子视图未指定要包装的大小。 Try specifying a fixed size just to see if the problem goes away, then go from there. 尝试指定固定大小,只是看问题是否消失,然后再从那里消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM