2016-04-15 32 views
0

我試圖插入一個文本字段或按鈕到一個小的佈局欄,但由於某種原因它沒有顯示。試圖將文本字段添加到小布局?

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


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:background="#767eca"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text = "Ankosh" 
      android:textColor="#ffffff" 
      android:textSize="20sp"></TextView> 
</RelativeLayout> 
    </LinearLayout> 
+0

什麼不顯示? –

+0

爲什麼在背景後關閉relativeLayout?如果textview應該放在裏面,那麼不需要... – Opiatefuchs

+0

提供方向 - 垂直或水平到線性佈局。 如果你想爲textview指定一些高度,最好將它提供給textview本身,而不是父級佈局。 – Ankita

回答

1

你必須改變內部相對佈局的高度,或將其標記爲wrap_content

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


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#767eca"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text = "Ankosh" 
      android:textColor="#ffffff" 
      android:textSize="20sp"></TextView> 
</RelativeLayout> 
    </LinearLayout> 
+1

查看此答案。 –

0

變化layout_height爲wrap_content,如果你想TextView的高度50dp然後用這裏面的TextView

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#767eca"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:text = "Ankosh" 
     android:textColor="#ffffff" 
     android:textSize="20sp"></TextView>