2016-04-15 35 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>