2013-02-27 67 views
0

我试图实现下图中右侧的布局。我目前得到的是在左边。视图没有采用与父亲相同的高度RelativeLayout

screenshot

这里是我的布局:

<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(浅绿色就是突出的透明区域):

9 patch drawable

RelativeLayout作为一个012的项目模板。代码中正在填充garment_grid_item_imagegarment_grid_item_on_loan是右上角的紫色三角形,其可见性由代码控制。

底部的View使用了9个补丁,这是我遇到的问题之一。我希望它和父母RelativeLayout一样高,但match_parentfill_parent都不起作用。我能做些什么来实现它的工作?

+1

你可不可以把'android:background =“@ drawable/item_border”'放到'RelativeLayout'而不是使用另一个'View'内?或者我错过了你在这里做什么? – Rawkode 2013-02-27 12:51:27

+0

这将涉及设置填充它将不得不改变不同的屏幕尺寸。我想使用3个不同的9个补丁映像(xhdpi,hdpi,mdpi)。 – boz 2013-02-27 13:29:32

回答

0

我刚刚尝试过一些类似图像的布局,并且在作为活动的根元素进行设置时工作正常。

这可能与您的RelativeLayout具有wrap_content作为其大小,并且未指定要包装的大小。尝试指定一个固定的大小来查看问题是否消失,然后从那里开始。