2015-02-23 69 views
1

顯示我有一個TextView其正常工作,但如果我試圖表明TextViewRelativeLayout它不顯示。(「//本節開始和結束」)的TextView不RelativeLayout的

XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:materialdesign="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#FFF" 
android:orientation="vertical"> 

    <RelativeLayout 
     android:id="@+id/relativeLayoutMain" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

    <com.gc.materialdesign.views.ScrollView 
     android:id="@+id/scroll" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/relativeLayoutContent"> 

     <RelativeLayout 
      android:id="@+id/relativeLayoutContainer" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

      <com.gc.materialdesign.views.LayoutRipple 
       android:id="@+id/itemSimple" 
       android:layout_width="fill_parent" 
       android:layout_height="64dp" 
       android:background="#FFF" 
       android:clickable="true"> 

       <!--this section - begin--> 
       <RelativeLayout 
        android:layout_width="90dp" 
        android:layout_height="25dp" 
        android:layout_alignParentRight="true" 
        android:background="#e91e63" 
        android:paddingBottom="20dp"> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_alignParentRight="true" 
         android:gravity="center_horizontal" 
         android:layout_marginRight="7dp" 
         android:text="sample text" 
         android:textColor="#727272" 
         android:textSize="17dp"/> 

       </RelativeLayout> 
       <!--this section - end--> 

      </com.gc.materialdesign.views.LayoutRipple> 

     </RelativeLayout> 

    </com.gc.materialdesign.views.ScrollView> 

    </RelativeLayout> 

</LinearLayout> 

,如果我想此代碼的工作,我必須定義出更多的空間widthRelativeLayoutheight,但我不想。我希望我的RelativeLayout與我指定的widthheight一樣。

感謝...

+0

對於文本視圖請嘗試將寬度和高度設置爲'match_parent'。看看會發生什麼 – 2015-02-23 19:01:22

+0

在Relativelayout中只需添加'android:layout_below =「@ id/itemSimpleJelly」' – Psypher 2015-02-23 19:04:25

+0

@Ranjith看起來'RelativeLayout'在id爲'itemSimpleJelly'的自定義視圖中。 – 2015-02-23 19:07:36

回答

2

RelativeLayout25dp一個height20dp一個padding。意思是文本只剩下5dp - 不足以顯示字符。您需要減少padding或增加height

<!--this section - begin--> 
<RelativeLayout 
    android:layout_width="90dp" 
    android:layout_height="25dp" <-------------------------------- 
    android:layout_alignParentRight="true" 
    android:background="#e91e63" 
    android:paddingBottom="20dp"> <-------------------------------- 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:gravity="center_horizontal" 
     android:layout_marginRight="7dp" 
     android:text="sample text" 
     android:textColor="#727272" 
     android:textSize="17dp"/> 

</RelativeLayout> 
<!--this section - end--> 
+1

謝謝。我總是忘記'padding'存在:) – 123 2015-02-23 19:10:24

1

不能使用高度和寬度的那些價值爲您RelativeLayout,有一個簡單的解釋:你正在使用25dpRelativeLayoutheight20dppadding-bottom5dp對於文本大小爲17dpTextView是不夠的。現在這個決定是你的。您可以從該RelativeLayout刪除填充底部或增加他的height或減少textSize。我認爲刪除填充是最好的解決方案:

<RelativeLayout 
    android:layout_width="90dp" 
    android:layout_height="25dp" 
    android:layout_alignParentRight="true" 
    android:background="#e91e63"> 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:gravity="center_horizontal" 
     android:layout_marginRight="7dp" 
     android:text="sample text" 
     android:textColor="#727272" 
     android:textSize="17dp"/> 

</RelativeLayout> 
相關問題