2013-10-15 41 views
0

我有一个android布局,其中有一些其他随机事物,并在中间部分我有一个linearLayout包含4个RelativeLayouts像下面的XML代码。RelativeLayout不能按预期工作

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left|center_vertical" 
     android:background="@drawable/backgroudpng"> 

    </RelativeLayout> 
</LinearLayout> 

这就是说,当我试图把对象在这个相对布局这下山。当我将一个对象放入它时,它将该对象放置在布局的另一部分(而不是我拖动到的地方!)。因此,例如,如果我将一个文本框放到相对布局的右上角,它可能会将其置于右下角或中心位置...

我以太需要得到这个工作或我需要一种不同的方法。我的目标是创建一个自定义排序按钮,让我可以同时在上面显示三个或四个不同的文本对象。

我试图做(我可以借鉴它在GIMP如果你需要我太)

______________________________________________________________________________________ 
|                      | 
| Some information here                | 
|            picture of a number from 1-10 here | 
| Something else about the "button here"            | 
|                      | 
|_____________________________________________________________________________________| 

无论如何,我想使用从表面上看瓶坯这一点,但似乎有些过度。基本上我只想创建4个这样的大型可点击界面,其中显示了可以通过单击它们设置的一些设置。无论如何,如果这是做错的方法,请让我知道!虽然这似乎是一个简单的方法来做到这一点,这正是我所希望的!

UPDATE:

这里就是我试图完成的快速图片:

enter image description here

的浅棕色表示背景图像,黑色代表整个视图背景,然后文本只是示例文本。我希望他们能够像按钮一样点击此视图并更改这些设置后面的设置。我遇到的问题是我将拖动一个小文本对象到我想要的“类型”设置的位置,当我放开它时,它被放置在“行影响”应该位置。

今晚我会尝试下面建议的方法,看看他们是否纠正了这个问题。

感谢您的帮助!

更新2:

下面是代码,还有什么它产生的图片(我已经验证了,它看起来像这样我的手机上使用,以及另一部手机和一个仿真器)

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/buttonbackground"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="Small Text" 
     android:id="@+id/textView" 
     android:textColor="#debabc" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_marginLeft="20dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="Small Text" 
     android:id="@+id/textView2" 
     android:layout_marginRight="21dp" 
     android:textColor="#dec1db" 
     android:layout_below="@+id/textView3" 
     android:layout_alignParentRight="true"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="Small Text" 
     android:id="@+id/textView3" 
     android:textColor="#debabd" 
     android:layout_alignBaseline="@+id/textView" 
     android:layout_alignBottom="@+id/textView" 
     android:layout_toLeftOf="@+id/textView2"/> 
</RelativeLayout> 

enter image description here

蓝色的盒是大致相当于我把文本,虽然仅仅是明确的,他们是repositi在X和Y访问上都提供。

此外,这是使用Android Studio,但我检查并加载在eclipse中的布局,它也在做同样的事情。这很奇怪,因为我之前使用过它们,并没有遇到过这种麻烦......我一定在做错事。

附加信息: 试图渲染它与API14,16和18。

再次感谢!

+0

大的可点击的界面会有背景吗? –

+0

这就是主意。在我的例子中,它只是一个坚实的颜色盒子。这样它看起来像一个按钮。我已经用照片更新了我的帖子,试图更好地解释我正在尝试做什么。 – Klaven

+0

在开始添加视图之前,显示实际导致您问题的XML而不是XML的片段可能会产生更好的答案。 –

回答

1

使用相对布局作为根布局而不是您已使用的线性布局。它会让你更容易管理其他布局。

0

不要和RelativeLayout一起去。根据您的要求。两行的表格布局给出了更好的结果。也很容易使用。它不会以不同的屏幕尺寸混淆您的布局。

+0

这也不能正常工作,我似乎不能一直扩大到屏幕的底部。我设置布局高度来包装内容,但它仍然只是将9补丁图形一直延伸到底部。 – Klaven

+0

我会创建您所需的布局,并将其发布给我自己。 –