<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gravity="center"> <Button android:id="@+id/t1" 
    android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:text="用户名"/> <Button android:id="@+id/textname2" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
android:text="2222" 
android:layout_toLeftOf="@id/t1"  />

</RelativeLayout>
请问代码有什么问题吗  为什么效果出不来呢  效果应该是“222”在“用户名”的左边啊  

解决方案 »

  1.   

    这样不行,把222的button和用户名button换下了。
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:gravity="center"><Button android:id="@+id/t1"  
    android:layout_toRightOf="@id/textname2" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"  
    android:text="用户名"/><Button android:id="@+id/textname2"  
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="2222" 
    /></RelativeLayout>或者在222上加上靠左相对于整个RelativeLayout属性
      

  2.   

    是啊 刚刚搞的  那个butto位置没设定 怎么设定呢  帮帮忙啊
      

  3.   

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent" android:layout_height="fill_parent"
     android:gravity="center"
     android:orientation="horizontal">     <Button android:id="@+id/textname2"  
    android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="2222" 
    android:layout_toLeftOf="@id/t1" />
     <Button android:id="@+id/t1"  
    android:layout_width="wrap_content"
     android:layout_height="wrap_content"  
    android:text="用户名"/></LinearLayout>
    这样写 试过 都能显示
      

  4.   

    你用户名那个Button默认是在左上角的,你那个2222的buton设置成toLeftOf第一个Button,你说这能显示出来嘛?比左上角更左的地方
      

  5.   

    搞定了  但是对布局还是不太会用啊   请问大侠们  LinearLayout RelativeLayout  TableLayout 什么时候用对应用哪一个合适呢 ?求解啊
      

  6.   

    LinearLayout RelativeLayout看个人喜好了,RelativeLayout布局可以直接拖控件定位,相对LinearLayout快捷多了。TableLayout要是做成表格一样的效果。