【发布时间】:2012-07-31 21:52:40
【问题描述】:
我的布局有问题。我有这个结构:
<ScrollView>
<LinarLayout>
<Button/>
<RelativeLayout>
<ImageButton/>
<ImageButton/>
<ImageButton/>
</RelativeLayout>
</LinarLayout>
</ScrollView>
我希望三个 ImageButtons 居中,一个并排,如下所示:
IMG1 IMG2 IMG3
为此,我使用android:gravity="center" 将RelativeLayout 中的元素居中,并使用android:layout_toRightOf="@+id/element" 和android:layout_toLeftOf="@+id/element" 按我想要的方式对元素进行排序。
当我在GraphicalLayout 选项上检查结果时,它显示的正是我想要的(我从来没有遇到过这个视图的问题,它总是显示我在XML 文件),但随后我编译并执行,一切都是无序的。我已经尝试了很多不同的方式来排序元素,但它正在做它想做的事情......这是我近两年的开发中第一次发生这种情况。
我也关闭了 Eclipse,但没有任何改变。
编辑以添加信息
我希望元素是这样的:
IMG1 IMG2 IMG3
在 GraphicalLayout 中一切正常,但在模拟器中,三个 IMGS 重叠。
这是完整的代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bugbox_wall_port" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/writeNewMsg"
android:layout_margin="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp" >
<ImageButton
android:id="@+id/spyMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgspy" />
<ImageButton
android:id="@+id/playerMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/msgplyr"
android:layout_toRightOf="@+id/spyMsgs" />
<ImageButton
android:id="@+id/allyMsgs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msgally"
android:layout_toRightOf="@+id/playerMsgs" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
不知道怎么解决。快把我逼疯了。这种布局有什么问题?为什么元素没有排序?我该如何解决它并像往常一样对元素进行排序?
有人可以帮我吗?
提前谢谢你!
【问题讨论】:
-
那么您的问题到底是什么?我不完全明白。
-
@0gravity 编辑了更多信息!
-
3张图片一定要水平居中吗?
-
@0gravity 是的,它们必须水平居中。
-
这是一张图片,它将以图形方式解释我的问题:imageshack.us/photo/my-images/198/sinttulo2kv.jpg
标签: android xml android-layout android-relativelayout