2013-03-02 137 views
0

我设计一个布局,共有4 RelativeLayout的一个是外盖,3是它的孩子。当我在外部布局中放置白色比没有剩余空格时,但是当我将9patch图像设置为可绘制图像时,会留下较少的默认填充/边距。有没有适当的解决填充/保证金问题?我曾尝试缘阴性,但它会隐藏位布局,我认为这是不妥当的解决办法,这是我的布局的Android RelativeLayout的设计问题

enter image description here

当我把白色作为背景比我的布局看起来像

这里我的布局下面的代码

enter image description here

<RelativeLayout 
     android:id="@+id/DetailSection1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/HeaderLayout" 
     android:layout_toLeftOf="@+id/DetailSection2" 

     > 

     <TextView 
      android:id="@+id/lblRestaurantName" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/DetailSection1" 
      android:layout_marginLeft="5dp" 
      android:layout_marginTop="5dp" 
      android:textColor="@color/heding_font" 
      android:textSize="@dimen/headingFont" 
      android:text="Restaurant Name" /> 

     <ImageView 
      android:id="@+id/imgpin" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/lblRestaurantName" 
      android:layout_margin="5dp" 
      android:src="@drawable/pin" /> 

     <TextView 
      android:id="@+id/lblAddress" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/lblRestaurantName" 
      android:layout_marginTop="5dp" 
      android:layout_toRightOf="@+id/imgpin" 
      android:text="Address" 
      android:textColor="@color/restaurant_list_font" 
      android:textSize="@dimen/lableNormalFont" 
      /> 

     <ImageView 
      android:id="@+id/imgphone" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/lblAddress" 
      android:layout_margin="5dp" 
      android:src="@drawable/phn" /> 

     <TextView 
      android:id="@+id/lblMobile" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/lblAddress" 
      android:layout_marginTop="5dp" 
      android:layout_toRightOf="@+id/imgphone" 
      android:text="Mobile" 
      android:textColor="@color/restaurant_list_font" 
      android:textSize="@dimen/lableNormalFont" 
      /> 

     <ImageView 
      android:id="@+id/imgstar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@+id/lblMobile" 
      android:layout_margin="5dp" 
      android:src="@drawable/star" /> 

     <TextView 
      android:id="@+id/lblStar" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/lblMobile" 
      android:layout_marginTop="5dp" 
      android:layout_toRightOf="@+id/imgstar" 
      android:text="Star" 
      android:textColor="@color/restaurant_list_font" 
      android:textSize="@dimen/lableNormalFont" 
      /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/DetailSection2" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_alignBottom="@+id/DetailSection1" 
     android:layout_toLeftOf="@+id/DetailSection3" 
     android:layout_toRightOf="@+id/lblStar" > 

     <ImageView 
      android:id="@+id/imgmore" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:src="@drawable/read_more" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/DetailSection3" 
     android:layout_width="95dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_below="@+id/HeaderLayout" 
     android:layout_gravity="center" 
     android:layout_centerInParent="true" 
     android:background="@drawable/photo_cover" > 

     <ImageView 
      android:id="@+id/imgRestaurant" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/lblMobile" 
      android:layout_margin="5dp" 
      android:src="@drawable/rihanna" /> 
    </RelativeLayout> 
</RelativeLayout> 
+0

可以请你发布的9补丁绘制你正在使用 – 2013-03-02 05:37:58

+0

做你尝试给了高度的根RelativeLayout的宽度= fillparent和相同的。 – Prateek 2013-03-02 05:41:11

+0

谢谢!Archie.bpgc我已经编辑了我9个补丁图像 – 2013-03-02 05:44:40

回答

2

从您发布的9-补丁可绘制的图像:

底线其指示在水平视数据群不是从左侧的起始点绘制。

我不知道这件事。而且我知道我在解释上述路线时并不清楚。

只是检查:

考虑以下9补丁被用作一个TextView的背景。如果你在其中放置一些文本,它将从绘制底线的区域开始。这意味着它将从左侧开始并一直走向右侧。

enter image description here

如果您使用以下9个补丁作为背景,并尝试你上面做同样的事情。将导致文字不从左边写入。它留下一点填充。

enter image description here

这就是为什么你会得到这样的结果的原因。当然,我对此100%肯定。

所以,只要找出这是否正常工作。尝试改变底线以填充完整图像。

+0

谢谢! Archie.bpgc。抱歉回复晚了!你的描述是正确的。我只是改变我的9补丁图像,我的问题解决了! – 2013-03-05 06:54:22

0

我认为你最好应用你想要的布局的背景颜色。并且还要保留代码,以便我们能够轻松地理解你的问题。

+0

感谢丹尼的问题!为了回答。因为它有一个阴影效果,所以我需要9个补丁图像。 – 2013-03-02 05:27:42

+0

丹尼,我编辑了我的问题,并把我的布局代码 – 2013-03-02 05:29:53