首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

相对布局显示的有关问题.求指导求教育.

2013-06-26 
相对布局显示的问题..求指导求教育...如题, 麻烦大家看看小弟下面这个布局哪里不对,,怎么就只能显示Button

相对布局显示的问题..求指导求教育...
如题, 麻烦大家看看小弟下面这个布局哪里不对,,怎么就只能显示Button1和Button2呢?


<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/button1"
???? ???android:layout_width="wrap_content"
???? ???android:layout_height="wrap_content"
??? ? ? ? ? android:text="button1"
???? ???/>
??? ?
??? <Button android:id="@+id/button2"
???? ???android:layout_width="wrap_content"
???? ???android:layout_height="wrap_content"
???? ???android:text="button2"
???? ???android:layout_toRightOf="@id/button1"
???? ???android:layout_below="@id/button1"
???? ???/>
??? ?
??? <Button android:id="@+id/button3"
???? ???android:layout_width="wrap_content"
???? ???android:layout_height="wrap_content"
???? ???android:text="button3"
???? ???android:layout_toRightOf="@id/button1"
???? ???android:layout_above="@id/button1"
???? ???/>
??? ?
??? <Button android:id="@+id/button4"
???? ???android:layout_width="wrap_content"
???? ???android:layout_height="wrap_content"
???? ???android:text="button4"
???? ???android:layout_toLeftOf="@id/button1"
???? ???android:layout_below="@id/button1"
???? ???/>
??? ?
??? ?
??? <Button android:id="@+id/button5"
???? ???android:layout_width="wrap_content"
???? ???android:layout_height="wrap_content"
???? ???android:text="button5"
???? ???android:layout_toLeftOf="@id/button1"
???? ???android:layout_above="@id/button1"
???? ???/>
</RelativeLayout>
relativelayout 布局
[解决办法]
<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/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="button1" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/button1"
        android:layout_toRightOf="@id/button1"
        android:text="button2" />



    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/button1"
        android:layout_toRightOf="@id/button1"
        android:text="button3" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/button1"
        android:layout_toLeftOf="@id/button1"
        android:text="button4" />

    <Button
        android:id="@+id/button5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@id/button1"
        android:layout_toLeftOf="@id/button1"
        android:text="button5" />

</RelativeLayout>


这样就可以了,试试吧
[解决办法]
你是想做成中间一个按扭,然后此按扭的四个方向对应一个么?
你试下一楼的写法 应该是可以 的。
如果不行,你button1和button2不是已经布好了么,然后其它的以button1和button2来相对,
比如说,1在中间,2在左上,3在左下: 3below1,同时3也与2左边对齐,以此类推。
另外,你可以看eclipse上写layout时可以直接看UI的

热点排行