2016-04-15 58 views
0

以下代码我添加文本视图或按钮时遇到问题。每次我尝试它时,都会在设计页面上出现该按钮位于手机外部。我插入一张图片以显示我在设计页面上的意思。文本字段或按钮出现在设计外部?

http://postimg.org/image/dtqbnoqxv/

<?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="40dp" 
     android:background="#767eca"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="label" 
      android:id="@+id/textView" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true"></TextView> 
    </RelativeLayout> 
<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button"></Button> 
</LinearLayout> 
+1

加上'机器人:方向=“垂直”''到LinearLayout'让'Button'来自下面的'TextView' – camelCaseCoder

+1

添加机器人:定位:在你的主直线布局 –

+0

“垂直”,通常也应该给一个如果未设置方向,则会发出皮棉警告。我想你已经在AS中禁用了lint警告,但应该启用.... – Opiatefuchs

回答

0

尝试增加机器人:方向= “垂直” 或Android:方向= LinearLayout中根据你的愿望的 “水平”。

<?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" 
    android:orientation="vertical"> 

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

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:text="label" 
      android:id="@+id/textView" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true"></TextView> 
    </RelativeLayout> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button"></Button> 
</LinearLayout>