XML是疯了。它没有显示元素的实际位置 [英] XML is crazy. It is not showing real position of elements

查看:125
本文介绍了XML是疯了。它没有显示元素的实际位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局问题。我有这样的结构:

I'm having problems with a layout. I have this structure:

<ScrollView>
    <LinarLayout>
        <Button/>
        <RelativeLayout>
            <ImageButton/>
            <ImageButton/>
            <ImageButton/>
        </RelativeLayout>
    </LinarLayout>
</ScrollView>

我想这三个ImageButtons中心,一个挨着另一个是这样的:

I want the three ImageButtons centered and one next to the other like this:

IMG1   IMG2   IMG3

为此,我中心的 RelativeLayout的使用安卓里面的元素:比重=中心我已经使用的android:layout_toRightOf =@ + ID /元素的android:layout_toLeftOf =@ + ID /元素命令元素我想要的方式。

For this purpose, I've centered the elements inside the RelativeLayout using android:gravity="center" and I've used android:layout_toRightOf="@+id/element" and android:layout_toLeftOf="@+id/element" to order the elements the way I want.

当我检查了 GraphicalLayout 选项的结果,它显示正是我想要的(我从来没有过这种观点的问题,它的总是显示的元素,因为我写的XML文件)但后来我编译并执行,这是所有无序。我尝试不同的方式来排列元素的很多,但它是做什么想...这是第一次发生在我身上几乎两年的发展。

When I check the result on the GraphicalLayout option, it is showing exactly what I want (I've never had problems with this view, it always shows the elements as I write on the XML file) but then I compile and execute and it is all disordered. I've tried a lot of different ways to order the elements but it is doing what it want... This is the first time it happened to me in almost two years of development.

我也关食,但也没什么改变。

I've also closed Eclipse but nothing's changed.

编辑添加的信息

我要的元素是这样的:

IMG1 IMG2 IMG3

在GraphicalLayout它是所有确定,但在模拟器三个IMGS是重叠的。

In the GraphicalLayout it is all ok but in the emulator the three IMGS are overlapping.

下面是完整的code:

Here's the complete code:

<?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>

我不知道如何解决它。我发疯。什么是与此布局的问题吗?为什么元素不排序?我怎样才能解决这个问题,并责令元素作为我常?

I do not know how to solve it. Is driving me nuts. What's the problem with this layout? Why the elements aren't ordered? How can I solve it and order the elements as I do always?

有人能帮助我吗?

感谢你在前进!

推荐答案

这也许是你在找什么:

<?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="#ffffff" >
    <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="wrap_content"
            android:layout_height="50dp"
            android:layout_gravity="center"
            android:padding="10dp" >
            <ImageButton
                android:id="@+id/spyMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/icon"/>
            <ImageButton
                android:id="@+id/playerMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"                
                android:background="@drawable/icon"
                android:layout_toRightOf="@id/spyMsgs" />
            <ImageButton
                android:id="@+id/allyMsgs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/icon"
                android:layout_toRightOf="@id/playerMsgs" />
         </RelativeLayout>
    </LinearLayout>
</ScrollView>

这篇关于XML是疯了。它没有显示元素的实际位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆