2013-02-24 57 views
0

我是Android新手,我试图在屏幕上移动一个按钮,但它不会让我把它放在我想要的地方,除此之外,我的所有文本当我移动这个按钮时盒子会移动..可以有人帮助我吗?在RelativeLayout上放置一个按钮

顺便说一句,我使用RelativeLayout。

这里是我做了什么:

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

    <TextView 
     android:id="@+id/TextView01" 
     android:layout_width="150dp" 
     android:layout_height="15dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_weight="0.09" 
     android:text="Name" 
     android:textAppearance="?android:attr/textAppearanceSmall" /> 

    <EditText 
     android:id="@+id/etSQLHotness" 
     android:layout_width="150dp" 
     android:layout_height="30dp" 
     android:layout_above="@+id/bSQLView" 
     android:layout_alignParentLeft="true" 
     android:ems="10" /> 

    <TextView 
     android:id="@+id/TextView02" 
     android:layout_width="100dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/TextView01" 
     android:layout_marginTop="54dp" 
     android:text="Age" /> 

    <EditText 
     android:id="@+id/etSQLName" 
     android:layout_width="150dp" 
     android:layout_height="30dp" 
     android:layout_above="@+id/etSQLHotness" 
     android:layout_alignParentLeft="true" 
     android:layout_marginBottom="38dp" 
     android:ems="10" > 

     <requestFocus /> 
    </EditText> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/TextView02" 
     android:layout_marginTop="24dp" 
     android:text="Hotness scale 1 - 10" /> 

    <Button 
     android:id="@+id/bSQLUpdate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="44dp" 
     android:layout_marginLeft="30dp" 
     android:layout_toRightOf="@+id/etSQLHotness" 
     android:text="Update SQlite Database" /> 

    <Button 
     android:id="@+id/bSQLView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/bSQLUpdate" 
     android:layout_toLeftOf="@+id/bSQLUpdate" 
     android:text="View" /> 

</LinearLayout> 
+5

欢迎来到SO。为了能够帮助您,我们需要通过发布相关代码和logcat输出来了解您的具体情况。在这种情况下,你的xml应该这样做。否则,我们不知道你设置了什么属性或其他任何可能使它无法工作的属性:) – codeMagic 2013-02-24 14:37:10

+0

告诉我们你做了什么 – moDev 2013-02-24 14:43:04

+1

你是否试图通过从调色板中拖放按钮..? – Pragnani 2013-02-24 14:44:21

回答

0
中相对布局

所有视图位置是相对于彼此,所以将它们之后,如果你会尝试移动视图的一个,其他所有视图依赖这将改变它们的位置,所以不是在图形布局中使用鼠标,而是相应地更改您的Xml,

+0

以及我真的不想要相对布局,如果是这样的话,我尝试linearLayout,但这导致我的按钮只是锁定...有没有什么办法,我可以拖放按钮/ textviews等自由xml到和然后放在我想要的地方? – 2013-02-24 16:10:20

+0

在android中自由拖拽n拖放不起作用,但使用布局,你可以把你所有的控件放在任何你想要的地方 – 2013-02-24 16:33:14

+1

为什么android会这样做?为什么他们没有使它像视觉基础,你可以自由地拖放东西? – 2013-02-24 16:42:41

相关问题