2013-03-02 191 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