2015-04-22 83 views
0

主佈局內的相關佈局在設備上顯示時不會填充父級高度。事實上,我想用黃色的左側佈局垂直填充行。 enter image description hereRelativeLayout與父母的身高不匹配

這裏是XML代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/verses_relativeLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 

<com.ad.holyquran.extra.TextViewEx 
    android:id="@+id/textView_Verse" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_toRightOf="@+id/versesRelativeLayout" 
    android:gravity="right" 
    android:layout_marginTop="-15dp" 
    android:paddingBottom="5dp" 
    android:paddingRight="5dp" 
    android:text="Text" 
    android:textSize="@dimen/versesTextSize" 
    android:textColor="#ff000000" /> 

<TextView 
    android:id="@+id/textView_VerseTranslation" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/textView_Verse" 
    android:paddingBottom="5dp" 
    android:gravity="fill_horizontal" 
    android:layout_centerHorizontal="true" 
    android:layout_toRightOf="@+id/versesRelativeLayout" 
    android:paddingRight="5dp" 
    android:paddingLeft="5dp" 
    android:paddingTop="5dp" 
    android:text="Text Text Text Text Text Text" 
    android:textSize="20sp" /> 

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:id="@+id/versesRelativeLayout" 
    android:layout_alignParentLeft="true" 
    android:background="#fff3f27f"> 

    <RelativeLayout 
     android:id="@+id/verseNumberIcRL" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <ImageView 
      android:id="@+id/versesImageView" 
      android:layout_alignParentTop="true" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/verse_number_ic" /> 

     <TextView 
      android:id="@+id/textView_verseNumber" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBottom="@+id/versesImageView" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:text="280" 
      android:paddingBottom="28dp" 
      android:textSize="14sp" 
      android:textColor="#ff000000" /> 
    </RelativeLayout> 
</RelativeLayout> 

感謝您的閱讀。

+1

我只是想你的XML代碼和佈局充滿高度..嘗試刪除第二個'RelativeLayout' ID ='verseNumberIcRL'我認爲這是不必要的..爲什麼你的自定義視圖'TextViewEx'設置爲'layout_marginTop =「 - 15dp」'?這可能是導致問題的原因。 –

+0

這是因爲我有兩個相似的佈局類似於verseNumberIcRL。 layout_marginTop =「 - 15dp」是因爲在設置字體之後,文本會從現在的位置下降15dp。 – Aalem

回答

0

如果刪除線

機器人:layout_toRightOf = 「@ + ID/versesRelativeLayout」

它將停止在右邊。如果你需要黃色作爲背景,那麼在主佈局(這是第一個relativeLayout)中將其設置爲背景使用 android:background =「@ drawable \ image」

您可能需要將所有其他元素在主RelativeLayout裏面。 希望這有助於。 我看不到主RelativeLayout的結束標記。

0

只需添加標籤佈局versesRelativeLayout:

android:layout_alignBottom="@+id/textView_VerseTranslation" 

<RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:id="@+id/versesRelativeLayout" 
      android:layout_alignParentLeft="true" 
      android:background="#fff3f27f" 
      android:layout_alignParentTop="false" 
      android:layout_alignParentBottom="false" 
      android:layout_alignBottom="@+id/textView_VerseTranslation" 
      > 
+0

只將佈局對齊到textview_VerseTranslation,頂部再次爲空。 – Aalem